I am pulling my hair! So before I break down and cry, I figured I'd ask for help in my favorite forum :)

I have a user login system where users can upload files. There are two types of users, admins and regular users. The admins can register new users and assign them folders that they're allowed to upload in. Admins can also edit users profiles if needed.

Where I'm getting stuck is that when I'm on the edit user page as an admin, I list out the available folders which is fine, but what I'm trying to accomplish is that I want to show the admin which folders the user currently is assigned. I'm having a hard time relaying this into code.

// grab the folders that have been access to the user (multiple folders can be assigned to a single user)
$sql3 = "SELECT access.folder_id FROM access INNER JOIN folders ON access.folder_id = folder.folder_is WHERE user_id = '$id'";
$result3 = mysql_query($sql3);

When you LEFT JOIN two tables, you get *all* the records from the left side table and then *only* records from the right side table that match the ON condition.

So in this case, you will get all the folder_id and folder_name values from the folders table. And then you will get only the record(s) from the access table where *both* the user_id is the one given (e.g., 1) and the folder_id matches one in the folders table (e.g., 1 and 3 in the data shown).

But now it gets sneaky:

When there IS NOT a match, then all the fields in the right side table (the "A" table in this query) will be NULL!!!

So we use the IF statement to test for that: If the value of A.folder_id is *NOT* null, then we give the output sel field a value of "selected". If A.folder_id *IS* null, then sel is the blank string.

And now we can simply dump the value of sel into the <option>s as we create them and all the ones that matched in the access table will indeed show as selected and the others won't.