I'm not that proficient at MySQL so I hope someone can help me- I have a database that keeps track of user accounts. I am trying to make it so that all the accounts with the same owner are deleted. This is defined as "owner". // First gather all users to delete from the table df_users: $adminusers = mysql_query("SELECT id FROM df_users WHERE owner=$docsuserid"); // I'm trying to locate all the rows whose owner equals the value of $docsuserid and save their id for use below. // This only pulls one record- I need to pull all that exist! // Now that we have all the user id's to delete, we need to delete every row from the table df_users_permissions whose id matches: mysql_query("DELETE FROM df_users_permissions WHERE id=$adminusers"); PHP: I know it's all wrong. My problems are: 1. My MySQL query is only pulling one record at a time 2. I need to get the rows to delete in the table df_users_permissions. (Should I be using some sort of foreach?? ) ANY help would be MUCH appreciated!!!
You just need to loop through your result set. $adminusers = mysql_query("SELECT id FROM df_users WHERE owner=$docsuserid"); // I'm trying to locate all the rows whose owner equals the value of $docsuserid and save their id for use below. // This only pulls one record- I need to pull all that exist! while($admin = mysql_fetch_array($adminusers)) { mysql_query("DELETE FROM df_users_permissions WHERE id=".$admin['id']); } PHP: If that doesn't work, change your second query to: mysql_query("DELETE FROM df_users_permissions WHERE id='".$admin['id']."');