I have two tables where one field links to an ID in the other table, and in this other table I would need to check if a value is valid or not. The tables look like this:
TABLE1
id - table2_id- deleted - user_id
TABLE2
id - is_valid
Now, I've tried using joins to no avail, but this is what I'm trying to accomplish:
Select a row (ID) from TABLE1 where deleted = 0, user_id = $id, and then I would need to take the table2_id of TABLE1 and go into TABLE2 on the row with the ID of table2_id and check if is_valid = 0.
I'd also need to limit results to 6 and have them chosen by random. Thanks in advance.
EDIT: Another way to visualize what I'm trying to accomplish:
$query = mysql_query("SELECT id, table2_id FROM table1 WHERE user_id = '$id' AND deleted = '0'");
while ($row = mysql_fetch_array($query)) {
$table2_id = $row['table2_id'];
$q = mysql_query("SELECT id FROM table2 WHERE id = '$table2_id' AND is_valid = '0'");
if ($q) $final_ids[] = $row['id'];
}