How to check if an id exists in another table
Posted: Fri Oct 08, 2010 7:11 am
I need php code to take the numbers from all rows of the column "id" from "wqw_users", then check whether these ids exist in the column "userid" from "wqw_items" and if they are other rows with different numbers to delete them. I already tried some things but it always deleted absolutely everything except the row with a userid 1 from "wqw_items", when there is an id 1 in "wqw_users" so it didn't delete it, but there are other ids too, so they also had to remain. Here is the code I used:
If anyone can help please respond. 
Code: Select all
$users = mysql_query ("SELECT * FROM wqw_users");
$all = mysql_fetch_assoc ($users);
$delete = mysql_query ("DELETE FROM wqw_items WHERE userid! =". $all ['id']."");