簡體   English   中英

在MySQL結果中創建可點擊的鏈接

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM