仅为PHP中的用户显示自己的数据


Display own data only for users in PHP

我目前已经做了一个页面,显示所有的用户,但我只想只显示当前登录的用户,请帮助我,我求求你,我花了4个小时没有什么T_T我新的在php和我很失落,我现在很绝望

<?PHP
$customerquery=mysql_query("select * from customerinfo");
while($customerrows=mysql_fetch_array($customerquery)){
?>
<tr>
<td>Id</td><td>First Name</td><td>Last Name</td><td>Address</td><td>Contact No</td>   <td>Username</td><td>Password</td><td>Edit</td>
</tr>
<tr>
<td><?PHP echo $customerrows['id'];?></td>
<td><?PHP echo $customerrows['fname'];?></td>
<td><?PHP echo $customerrows['lname'];?></td>
<td><?PHP echo $customerrows['address'];?></td>
<td><?PHP echo $customerrows['contactno'];?></td>
<td><?PHP echo $customerrows['username'];?></td>
<td><?PHP echo $customerrows['password'];?></td>
<td><a href="edit2.php<?PHP echo '?id='.$customerrows['id']; ?>">edit</a></td>
</tr>
<?PHP } ?>

您需要在查询中指定WHERE条件。这将只获取一行,因此不需要while循环:

$id = (int) $_GET['id']; // assuming you pass user id in URL
$customerquery = mysql_query("select * from customerinfo WHERE id = $id");
$customerrows = mysql_fetch_array($customerquery);
// rest of your html