首页 > 解决方案 > 使用 PHP 从 SQL 数据库中获取 url 时如何引入锚链接?

问题描述

这是 PHP 脚本,我可以将数据加载到数据库中,但链接行中的元素似乎不可点击。所以我重定向了用户。我的尝试是添加类似于表定义的 anchor() 标签,但它仍然处于非活动状态。

<?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);
?>

标签: phphtmlmysqlhtml-table

解决方案


如果您不知道,请在这里学习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>';

推荐阅读