我正在学习一些编码。我正在寻找创建可点击的 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/