php - 在 MySQL 结果中创建可点击的链接

标签 php mysql hyperlink

我正在学习一些编码。我正在寻找创建可点击的 MySQL 结果的结果。我希望姓名(名字和姓氏)是“可点击的”,以便他们可以链接到客户记录进行查看。预先感谢您的帮助!

<table class="list"; > 
      <tr>
        <th>Name</th>
        <th>Address</th>
        <th>Email</th>
        <th>Phone</th>
    </tr>

    <?php while($customers = mysqli_fetch_assoc($customer_set)) { ?>
        <tr>
            <td><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></td>
            <td><?php echo h($customers['address1']. ' '.$customers['city'].', '.$customers['state'].' '.$customers['zip']); ?></td>
            <td><?php echo h($customers['email1']); ?></td>
            <td><?php echo h($customers['phone1']); ?></td>

        </tr>

    <?php } ?>

谢谢

最佳答案

如果您想要可点击的名字和姓氏,那么您需要添加带有查看网址的 anchor 标记,如下例所示。

示例(分别发送名字和姓氏)

<td><a href="view-record.php?fname=<?php echo h($customers['first_name'] ?>&lname=<?php echo h($customers['last_name'] ?>"><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></a></td>

更好的解决方案是您可以发送用户的 id 。例如,我假设您在客户表中有一列id,那么您可以像下面的示例一样传递id

<td><a href="view-record.php?uid=<?php echo $customers['id']; ?>"><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></a></td>

注意:您可以使用一些哈希方法对 id 进行加密,以安全地传递用户的 id。

现在,当您单击这些链接时,您将重定向到 View 页面,您可以在其中使用 GET 方法获取这些 ID 或名字、姓氏。

示例

view-record.php

<?php 
  if(isset($_GET['uid'])) {
     $userid = $_GET['uid']; //please add some validation before using this value.
   }
?>

关于php - 在 MySQL 结果中创建可点击的链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52509866/

相关文章:

php - 任何支持 5.3 语法的 PHP 编辑器?

php - 插入记录时创建 slug 以包含 id 和 title - php MySQL

php - 如何编写此查询?

mysql - 如何避免使用此基本内部联接进行全表扫描?

html - 链接到 Web 应用程序中的本地内容

php - 让javascript在外部链接点击时运行?

php - 如何将小时数添加到 mysql 数据库的时间戳类型字段

php - 我正在用 PHP 做在线测验类型的脚本。最好使用 cookie 或 session

twitter - YouTube Twitter 社交媒体图标错误

mysql - 为数据库中的每封电子邮件获取适量的啤酒