MySQL Forums
Forum List  »  PHP

Creating an array variable from SQL results to use with NOT IN() function.
Posted by: Clark Hull
Date: June 06, 2013 11:25PM

I'm trying to create an array variable from a simple SQL query to use in a NOT IN() function in another SQL query. I have an ID field in Table 2 that corresponds to an ID field in Table 1. The relationship is Table 1 one to Table 2 many. I have been successful creating the second SQL query however, I only get the last ID from Table 2.

Here is an example of my code:

$query = "SELECT * FROM Table2 WHERE `mbr_member_id` = '$v_mbr_id'";
$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result))
{
$variable = $row['friend_of'];
}

$rand_mbr = "SELECT * FROM Table1 WHERE `act`='Y' AND `lck`='N' AND `member_id` != '$v_mbr_id' AND `member_id` NOT IN ('$variable') ORDER BY RAND() LIMIT 5";

Any help would be greatly appreciated.

Options: ReplyQuote


Subject
Written By
Posted
Creating an array variable from SQL results to use with NOT IN() function.
June 06, 2013 11:25PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.