Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

How do i create a link

  • 30-01-2009 04: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,277 ✭✭✭✭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