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

时间:2018-07-27 12:42:49

标签: php html session session-variables session-cookies

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

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,但是如何?我应该传递查询或新变量还是什么?

1 个答案:

答案 0 :(得分: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'];