Results into variables?

I have 5 tables. I need to select the 4 most recent posts from one table and get the ID for those posts in four separate variables to use for queries from the other tables:

SELECT userid FROM table1 WHERE subcategory = “$input” ORDER BY id DESC LIMIT 4;

So there I have what I need. Now how can I assign those four userid results to new variables to be used in future queries on that same page:

SELECT * FROM table2 WHERE userid = $userid1;
SELECT * FROM table2 WHERE userid = $userid2;
SELECT * FROM table2 WHERE userid = $userid3;
SELECT * FROM table2 WHERE userid = $userid4;

Got it:

$result = mysql_query(“SELECT id, name FROM users ORDER BY id DESC LIMIT 4”);

while ($row = mysql_fetch_array($result)){
echo “$row[0] $row[1]
”;
}

Sponsor our Newsletter | Privacy Policy | Terms of Service