Skip to content
Advertisement

How introduce anchor links when fetching a url from SQL database using PHP?

This is the PHP script and I can load my data in database but elements in the Link row seems not clickable .so that I redirect the user. My attempt was to add anchor() tags similar to table definition but its still inactive.

<?php
$con=mysqli_connect($server,$user,$password,$dbname);
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM accident_log");

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Link</th>
</tr>";

while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<a><td>" . $row['Link'] . "</td></a>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

Advertisement

Answer

Learn here if you do not know https://www.w3schools.com

echo '<td><a href="' . $row['link'] . '">' . $row['link'] . '</a></td>';
echo '<td><a href="' . $row['link'] . '" style="background: #09f; color: #fff; padding: 10px 20px;">' . $row['link'] . '</a></td>';
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement