1

こんにちは、クエリを使用してユーザー ID の配列を作成しています。別のクエリを使用して、最初のクエリから作成された配列にある user_id である特定のテーブルから選択したいと思います。WHERE 句で配列を使用するにはどうすればよいですか?

参考までに: $row_interest は配列です

私のコード:

//Grabs the user id's of the users that have the queried interest
$interest_search_query= "SELECT DISTINCT user_id FROM interests WHERE interest LIKE   
'%".$search_term."%'";
$interest_search_result= mysqli_query($connect, $interest_search_query);
$row_interest= mysqli_fetch_array($interest_search_result);

//Grabs the user information with each user id
$search_query= "SELECT DISTINCT user_id, fname, lname, profile_pic, school FROM users   
WHERE user_id IN $row_interest";

「WHERE user_id IN $row_interest」を試してみましたが、うまくいかないようです。私は何が間違っているのでしょうか?

ありがとう。

4

4 に答える 4

3
$search_query= "SELECT DISTINCT user_id, fname, lname, profile_pic, school FROM users   
WHERE user_id IN (".implode(',',$row_interest).")";
于 2013-05-29T22:47:59.477 に答える
2

実際に両方のクエリをマージできます。

SELECT distinct user_id, fname, lname, profile_pic, school
FROM users
WHERE user_id in 
    (SELECT distinct user_id from interests
    where interest like %{search_term}%)
于 2013-05-29T22:50:44.120 に答える