当用户单击数据表中的“查看链接”时,在PHP页面中查看详细信息

问题描述 投票:0回答:1

我有以下代码,它从数据库中获取并显示数据表。在每个用户旁边,我有“查看”链接,它显示详细信息页面。

if ($role == 'Manager' && isset($_GET['click'])){
 if ($_GET['click'] == 'ViewRequests'){
  $sql="SELECT users.user_id, users.first_name, users.middle_name, users.last_name, request.emp_id, request.location, request.asset_kind, request.Status
  FROM users
  INNER JOIN request ON users.user_id=request.emp_id AND users.role IN ('Employee','Admin') AND request.Status='Request';";
  $records=mysql_query($sql);
  ViewRequest($records); 
  }}                                                                    
     function ViewRequest($records){
       echo "<table width='600' border='1' align='center' cellpadding='1' cellspacing='1' style='top:-150px;'>
<h1 align='center'>View Requests</h1>
<tr><th>User id</th><th>Employee Name</th><th>Location</th><th>Asset Kind</th><th>Status</th><th>    </th></tr>";
   while ($row=mysql_fetch_assoc($records)){
    echo "<tr>";
    echo "<td>".$row['user_id']."</td>";
    echo "<td>".$row['first_name']."    ".$row['middle_name']."    ".$row['last_name']."</td>";
    echo "<td>".$row['location']."</td>";
    echo "<td>".$row['asset_kind']."</td>";
    echo "<td>".$row['Status']."</td>";
    echo "<td> <a href='view.php'>VIEW</a></td>";       
    }echo "</tr>";}echo "</table>";

当用户点击“查看”链接时,它应显示每个用户的特定信息。我怎么能在PHP中实现这个?..我知道我必须使用SESSION但是如何?我应该通过查询或新变量或什么?

php html session session-variables session-cookies
1个回答
1
投票

如果您的用户ID是唯一的,那么您可以将其作为参数传递:

while ($row=mysql_fetch_assoc($records)){
  echo "<tr>";
  echo "<td>".$row['user_id']."</td>";
  echo "<td>".$row['first_name']."    ".$row['middle_name']."    ".$row['last_name']."</td>";
  echo "<td>".$row['location']."</td>";
  echo "<td>".$row['asset_kind']."</td>";
  echo "<td>".$row['Status']."</td>";
  echo "<td> <a href='view.php?user_id=". $row['user_id']."'>VIEW</a></td>";       
}

然后在view.php

if(isset($_GET['user_id']) $user_id = $_GET['user_id'];
© www.soinside.com 2019 - 2024. All rights reserved.