在mysql结果中创建一个可点击的链接

vx6bjr1n  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(307)

我正在学习一些编码。我期待着创建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 } ?>

谢谢,

uelo1irk

uelo1irk1#

你需要使用 <a> (锚定)html标记如下:

<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><a href="http://example.com/customer/id/<?php echo $customers['id']; ?>"><?php echo h($customers['first_name'].' '.$customers['last_name']); ?></a></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 } ?>

替换url http://example.com/... 不管你想用哪个真实的网址链接。

jaql4c8m

jaql4c8m2#

如果你想点击的名字和姓氏,那么你需要添加锚标签与查看网址如下面的例子。
示例(分别发送名和姓)

<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 在customers表中,您可以像下面的示例一样传递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。
现在,当您点击这些链接时,您将在查看页面上重定向,在这里您可以使用get方法获得这些id或firstname、lastname。
例子
view-record.php文件

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

相关问题