我正在尝试构建一个系统,以显示与特定用户不是朋友的所有用户,以便用户只能看到并添加不是他们朋友的朋友。
但我的问题是代码只删除添加好友列表中的用户第一个朋友,它会在add friend_list中显示已经是他朋友的其他朋友。
if(isset($_SESSION['em'])){
$eml = $_SESSION['em'];
$list = "select friend_id,user_id from friend";
$friend = mysqli_query($conn,$list);
$rowf = mysqli_fetch_assoc($friend);
$idf = $rowf['friend_id'];
$id = $rowf['user_id'];
$query = ("select id,fst,las,uid,pass,email,sts,ocp from Users where email!='$eml' AND id!='$idf' AND id!='$id'");
$res = mysqli_query($conn,$query);
if(mysqli_num_rows($res) > 0){
while($row = mysqli_fetch_assoc($res)){
$_SESSION['ids'] = $row['id'];
?>
<table id="list">
<tr>
<td id="id" style=" "><a href=""><?php echo $_SESSION['ids'].'<br>';?></a></td>
<td id="fst" style=""><a href="profile.php?uid=<?php echo $row['uid']; ?>">
<?php echo $row['fst'].'<br>'; ?>
</a></td>
<td id="las" style=""><?php echo $row['las'].'<br>';?></td>
<td id="uid" style=" "><?php echo $row['uid'].'<br>';?>
<form action="request.php" method="POST">
<a href="request.php?id=<?php echo $_SESSION['ids']; ?>"><input id="request" type="text" value="ADD" readonly></a></form></td>
<td id="email" style=" width:180px;height:40px;text-align:center;"><?php echo $row['email'].'<br>';?></td>
<td id="sts" style=""><?php echo $row['sts'].'<br>';?></td>
<td id="ocp" style=""><?php echo $row['ocp'].'<br>';?></td>
</tr>
</table>
<?php
}}}
?>
答案 0 :(得分:0)
您的代码稍有变化,请在下面尝试。我假设您正在使用会话变量eml,您希望获得与他不是朋友的用户。你可能需要更改user_id,friend_id,因为我不确定你指的是哪一个朋友。
if(isset($_SESSION['em'])){
$eml = $_SESSION['em'];
//$list = "select friend_id,user_id from friend";
//$friend = mysqli_query($conn,$list);
//$rowf = mysqli_fetch_assoc($friend);
//$idf = $rowf['friend_id'];
//$id = $rowf['user_id'];
$query = ("select id,fst,las,uid,pass,email,sts,ocp from Users u where email='$eml' AND id not in (select friend_id from friend where user_id=u.id)");
$res = mysqli_query($conn,$query);
if(mysqli_num_rows($res) > 0){
while($row = mysqli_fetch_assoc($res)){
$_SESSION['ids'] = $row['id'];
?>
<table id="list">
<tr>
<td id="id" style=" "><a href=""><?php echo $_SESSION['ids'].'<br>';?></a></td>
<td id="fst" style=""><a href="profile.php?uid=<?php echo $row['uid']; ?>">
<?php echo $row['fst'].'<br>'; ?>
</a></td>
<td id="las" style=""><?php echo $row['las'].'<br>';?></td>
<td id="uid" style=" "><?php echo $row['uid'].'<br>';?>
<form action="request.php" method="POST">
<a href="request.php?id=<?php echo $_SESSION['ids']; ?>"><input id="request" type="text" value="ADD" readonly></a></form></td>
<td id="email" style=" width:180px;height:40px;text-align:center;"><?php echo $row['email'].'<br>';?></td>
<td id="sts" style=""><?php echo $row['sts'].'<br>';?></td>
<td id="ocp" style=""><?php echo $row['ocp'].'<br>';?></td>
</tr>
</table>
<?php
}}}
?>