我正在我的网站上实现一个朋友列表系统,我已经让它显示已接受的朋友姓名(因此接受的值为 1),当我访问虚拟帐户时,我可以看到他们的朋友,但是当我我以虚拟帐户登录,我也可以看到,我什至手动将数据库中的 user_id 更改为“1”,然后注销并登录,发现它只能使用 1 的 user_id,这是代码。它还不是 MYSQLI,这是我的下一步。
<h1>Friends</h1>
<?php
$user_id = user_id_from_username($username);
if($_SESSION['user_id'] == $user_id){
$logged_user_id = $_SESSION['user_id'];
$result = mysql_query("SELECT * FROM `friends` WHERE `friend_id`='{$logged_user_id}' AND `user_id`!='{$logged_user_id}' AND `accepted`='1'");
while ($row = mysql_fetch_array($result)){
$friend_id = $row['user_id'];
/*Get friend details*/
$fetch_details = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `user_id`='{$friend_id}'"));
echo $fetch_details->username;
echo '<br/>';
}
}
else if($_SESSION['user_id'] != $user_id){
$user_id = user_id_from_username($username);
$logged_user_id = $user_id;
$result = mysql_query("SELECT * FROM `friends` WHERE `user_id`='{$logged_user_id}' AND `friend_id`!='{$logged_user_id}' AND `accepted`='1'");
while ($row = mysql_fetch_array($result)){
$friend_id = $row['friend_id'];
/*Get friend details*/
$fetch_details = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `user_id`='{$friend_id}'"));
echo $fetch_details->username;
echo '<br/>';
}
}
?>
表格
FRIENDS
id(AI)
user_id
friends_id
datemade
accepted(enum 0, 1)
USERS
user_id(AI)
username
profile
active