Search code examples
phpmysqlurlhref

How to output data from MySQL db into clickable links? Using PHP


How do I convert the data coming from mysql database (website_url) into clickable links?

<?php   
$sql = "SELECT * FROM sports";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
    echo "<table>";

    while($row = mysqli_fetch_array($result)){

       echo "<tr>";
                       echo "<td>" . $row  ['website_url'] .     "</td>"; 
       echo "</tr>";
        }
        echo "</table>";
    } 
 } 
mysqli_close($link);
?>

How do I make the URLs which are received from the database through this piece of code as clickable links?

 echo "<td>" .$row['website_url']. "</td>";

The data received from the database would be like:

Please help!


Solution

  • That's standard HTML, e.g.:

    $url = $row  ['website_url'];
    echo "<td><a href='" . $url . "'>" . $url . "</a></td>";
    

    You need to wrap links into a tags. Maybe you should start with a basic HTML tutorial to learn these things :)