我正在使用SELECT查询来创建值数组。然后我使用另一个选择查询,但我不想从返回中排除原始数组值。但我继续收到第二个查询错误。我正确地创建了数组吗?我的MySQL sytax是否正确?
我的PHP:
// Grabs all the users the logged in user is already friends with or following
$already_following_query= "SELECT recipient FROM relations WHERE sender= '".$user_id."'
AND status= '1' OR status= '2'";
$already_following_result= mysqli_query($connect, $already_following_query)
or die('Error with already following query');
$already_following_array= mysqli_fetch_array($already_following_result);
$suggestions_query= "SELECT * FROM users WHERE user_id NOT IN
'".$already_following_array."' AND user_id != '".$user_id."'";
$suggestions_result= mysqli_query($connect, $suggestions_query)
or die('Error with suggestions query');
答案 0 :(得分:2)
NOT IN
子句需要一个数组 - 你提供了一个字符串。
试试这个:
$array_following_array = implode(", ", $array_following_array);
$suggestions_query = "SELECT * FROM users WHERE user_id NOT IN ('".$already_following_array."') AND user_id != '".$user_id."'";