下面是我的查询,它返回会话用户的朋友。
$new_friends = $db->query("
SELECT user.id, user.name_surname
FROM user
JOIN friendship ON user.id = friendship.sender_id or user.id = friendship.receiver_id
WHERE (friendship.receiver_id =" . $_SESSION["SES_USER_ID"] . " OR friendship.sender_id =" . $_SESSION["SES_USER_ID"] . ")
AND user.id != " . $_SESSION["SES_USER_ID"] . "");
$new_friends->setFetchMode(PDO::FETCH_ASSOC);
$new_friends_data = $new_friends->fetchAll();
它运行良好,没有任何问题。现在我想用新的属性来改进我的网站,所以我想在我的网站上添加“新人”部分。获取的人不能会话用户的朋友和他/她自己。
我尝试将以下代码用于“您可能知道”部分。但它再次返回会话用户的朋友。
$new_friends2 = $db->query("
SELECT user.id, user.name_surname
FROM user
JOIN friendship ON user.id = friendship.sender_id or user.id = friendship.receiver_id
WHERE (friendship.receiver_id !=" . $_SESSION["SES_USER_ID"] . " OR friendship.sender_id !=" . $_SESSION["SES_USER_ID"] . ")
AND user.id != " . $_SESSION["SES_USER_ID"] . "");
$new_friends2->setFetchMode(PDO::FETCH_ASSOC);
$new_friends_data2 = $new_friends->fetchAll();
//look carefully I change some equations from = to !=
我该如何解决?
基本上我想返回不是会话用户朋友的人。