[英]create a clickable link in MySQL results
我正在学习一些编码。 我正在寻找可点击的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 } ?>
谢谢,
如果您想要可点击的名字和姓氏,那么您需要添加带有查看URL的锚标记,如以下示例所示。
示例(分别发送名字和姓氏)
<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>
更好的解决方案是您可以发送user的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。
现在,当您单击这些链接时,将在视图页面上重定向,在该页面上您可以使用GET方法获取这些ID或名字,姓氏。
例
视图record.php
<?php
if(isset($_GET['uid'])) {
$userid = $_GET['uid']; //please add some validation before using this value.
}
?>
您需要使用<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 } ?>
将网址http://example.com/...
替换为您要用于链接的任何实际网址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.