如何在网站上显示存储在 MySQL 数据库表中的网站链接,但显示为要点击的超链接?

这是我正在处理的代码演示,我在 MySQL 表中有链接,并希望在网站表上显示它们,但我不想显示链接,而是显示与 Excel 中的超链接相同的名称。

示例:如果我只使用 href=www.google.com链接

我的代码:

<!DOCTYPE HTML>

<html>

<head>

<title>Pagina teste</title>

<div align="center">

<font size="+3">Lista de Websites</font>

</div>

</head>

<body>

<style>

  table, td, th {border: 1px solid black; border-collapse: collapse; }

  tr:nth-child(even) {background-color: #dcdddd;}

</style>

<table>

<tr>

<th><font size="+2">Website Name</font></th>

<th><font size="+2">Link</font></th>

</tr>

<?php

$conn = mysqli_connect("localhost", "root", "", "test");

// Check connection

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);

}

if(isset($_GET['order'])){

    $order = $_GET['order'];

}else{

    $order = 'websitename';

}


if(isset($_GET['sort'])){

    $sort = $_GET['sort'];

}else{

    $sort = 'ASC';

}

$sql = "SELECT websitename, link FROM websites ORDER BY $order $sort";

$result = $conn->query($sql);

if ($result->num_rows > 0) {

// output data of each row

while($row = $result->fetch_assoc()) {

echo "<tr>

<td>" . $row["websitename"]. "</td>

<td>" . $row["link"]. "</td>

</tr>";

}

echo "</table>";

} else { echo "0 results"; }

$conn->close();

?>

</table>

</body>



</html>


千万里不及你
浏览 214回答 3
3回答

湖上湖

中国商店方法中的公牛,用标签标记包围输出:echo "<tr><td>" . $row["websitename"]. "</td><td><a href=\"" . $row["link"]. "\">" . $row['websitename'] . "</a></td></tr>";

慕哥9229398

尝试这个<!DOCTYPE HTML>&nbsp; &nbsp; <html>&nbsp; &nbsp; <head>&nbsp; &nbsp; <title>Pagina teste</title>&nbsp; &nbsp; <div align="center">&nbsp; &nbsp; <font size="+3">Lista de Websites</font>&nbsp; &nbsp; </div>&nbsp; &nbsp; </head>&nbsp; &nbsp; <body>&nbsp; &nbsp; <style>&nbsp; &nbsp; &nbsp; table, td, th {border: 1px solid black; border-collapse: collapse; }&nbsp; &nbsp; &nbsp; tr:nth-child(even) {background-color: #dcdddd;}&nbsp; &nbsp; </style>&nbsp; &nbsp; <table>&nbsp; &nbsp; <tr>&nbsp; &nbsp; <th><font size="+2">Website Name</font></th>&nbsp; &nbsp; <th><font size="+2">Link</font></th>&nbsp; &nbsp; </tr>&nbsp; &nbsp; <?php&nbsp; &nbsp; $conn = mysqli_connect("localhost", "root", "", "test");&nbsp; &nbsp; // Check connection&nbsp; &nbsp; if ($conn->connect_error) {&nbsp; &nbsp; die("Connection failed: " . $conn->connect_error);&nbsp; &nbsp; }&nbsp; &nbsp; if(isset($_GET['order'])){&nbsp; &nbsp; &nbsp; &nbsp; $order = $_GET['order'];&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; $order = 'websitename';&nbsp; &nbsp; }&nbsp; &nbsp; if(isset($_GET['sort'])){&nbsp; &nbsp; &nbsp; &nbsp; $sort = $_GET['sort'];&nbsp; &nbsp; }else{&nbsp; &nbsp; &nbsp; &nbsp; $sort = 'ASC';&nbsp; &nbsp; }&nbsp; &nbsp; $sql = "SELECT websitename, link FROM websites ORDER BY $order $sort";&nbsp; &nbsp; $result = $conn->query($sql);&nbsp; &nbsp; if ($result->num_rows > 0) {&nbsp; &nbsp; // output data of each row&nbsp; &nbsp; while($row = $result->fetch_assoc()) {&nbsp; &nbsp; echo "<tr>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<td>".$row["websitename"]."</td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<td><a href=".$row["link"]." target='_blank'>" . $row["link"]. "</a></td>&nbsp; &nbsp; </tr>";&nbsp; &nbsp; }&nbsp; &nbsp; echo "</table>";&nbsp; &nbsp; } else { echo "0 results"; }&nbsp; &nbsp; $conn->close();&nbsp; &nbsp; ?>&nbsp; &nbsp; </table>&nbsp; &nbsp; </body>&nbsp; &nbsp; </html>

蝴蝶不菲

您可以在表格内使用锚链接。<?php&nbsp; &nbsp; &nbsp; &nbsp;echo "<tr>&nbsp; &nbsp; &nbsp; &nbsp;<td>" . $row["websitename"]. "</td>&nbsp; &nbsp; &nbsp; &nbsp;<td><a href=".$row["link"]." target='_blank'>" . $row["link"]. "</a></td>&nbsp; &nbsp; &nbsp; &nbsp;</tr>";&nbsp; &nbsp; ?>
打开App,查看更多内容
随时随地看视频慕课网APP