Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

How do i create a link

  • 30-01-2009 3:22pm
    #1
    Closed Accounts Posts: 73 ✭✭


    How do i create a link in html where the source is in a MySQL database

    Lets say i have "www.joeblogs.com" stored in the database and when i query the DB and get the result i need the url to be a link.

    I use php, html, sql and MySQL



    Help please


Comments

  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Are you able to print the address to the screen OK? If so, then it's just a case of wrapping it in the correct HTML tag.

    [html]
    <a href="http://www.joeblogs.com">www.joeblogs.com</a&gt;
    [/html]

    As the "www.joeblogs.com" will be a PHP variable, you'll need to print it out - but I don't know the syntax for that in PHP.


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    Something like this would work -
    $db = mysql_connect("localhost", $db_user, $db_password) or die('Cannot connect to the database because: ' . mysql_error());
    
    $db_selected = mysql_select_db($db_name, $db);
    if (!$db_selected)
            die ('Cannot use database because: ' . mysql_error());
    
    $query = "select url from my_table";
    $result = mysql_query($query, $db);
    
    if (mysql_num_rows($result)!=0) {
            $row = mysql_fetch_array($result);
    
            // this will print a link to every url in the database
    
            echo "<a href=\"".$row['url']."\">".$row['url']."</a>";
    }
    

    You could write more efficient code to extract that data from the database, but hopefully the above will point you in the right direction.


  • Closed Accounts Posts: 73 ✭✭Protype


    This is what i get from the recordset
    <?php echo $row_rsMasterInfo; ?>

    this prints "www.site.com" when viewed on the localhost server

    I had the same with email link but all i did was ad mailto:
    <a href="mailto:"><?php echo $row_rsMasterInfo; ?></a>
    inserted the php and its grand.

    The website link just wont work


  • Closed Accounts Posts: 12,382 ✭✭✭✭AARRRGH


    Mailto is for e-mails.

    Try this instead:
    echo "<a href=\"mailto:".$row_rsMasterInfo['email1']."\">".$row_rsMasterInfo['email1']."</a>";
    

    Or this for a URL:
    echo "<a href=\"http://".$row_rsMasterInfo['website']."mailto:\">".$row_rsMasterInfo['Website']."</a>";
    


  • Closed Accounts Posts: 73 ✭✭Protype


    Thank you. worked fine


  • Advertisement
Advertisement