为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
千万里不及你 2022-10-09 17:17:41
这是我正在处理的代码演示,我在 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 connectionif ($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 rowwhile($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>
查看完整描述

3 回答

?
湖上湖

TA贡献2003条经验 获得超2个赞

中国商店方法中的公牛,用标签标记包围输出:


echo "<tr>

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

<td><a href=\"" . $row["link"]. "\">" . $row['websitename'] . "</a></td>

</tr>";


查看完整回答
反对 回复 2022-10-09
?
慕哥9229398

TA贡献1877条经验 获得超6个赞

尝试这个


<!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><a href=".$row["link"]." target='_blank'>" . $row["link"]. "</a></td>

    </tr>";

    }

    echo "</table>";

    } else { echo "0 results"; }

    $conn->close();

    ?>

    </table>

    </body>



    </html>


查看完整回答
反对 回复 2022-10-09
?
蝴蝶不菲

TA贡献1810条经验 获得超4个赞

您可以在表格内使用锚链接。


<?php

       echo "<tr>

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

       <td><a href=".$row["link"]." target='_blank'>" . $row["link"]. "</a></td>

       </tr>";

    ?>


查看完整回答
反对 回复 2022-10-09
  • 3 回答
  • 0 关注
  • 120 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信