Copy link to clipboard
Copied
Is there a way to serve up data for a user based on their group assignment? I have two SQL tables. The first one has the user login information (username, password, groupID note: multiple users can belong to same GroupID). The second table has the data that needs to be shown (file name, date, groupID note: multiple files can be assigned to same GroupID). I need to be able to serve up the file name and date from the second group based on the groupID assigned in the first table. I know this should be simple, but for some reason I just can't wrap my head around it. My site is PHP. Thank you in advance for any help,
Copy link to clipboard
Copied
You just need to join the two tables on the groupID. Look up SQL joins for more details. It's really quite simple.
Copy link to clipboard
Copied
Thanks! I can join the tables and it shows the matched items, but it's not
limiting to the logged in user (it's showing all documents for all
usergroups). Is there anyway to filter based on Usergroup? Sorry, I know
this should be easy... I'm having a blonde moment
Copy link to clipboard
Copied
The GroupID you are using is typically used as an access level and used for access and restriction to pages, but the same principles apply here. I would suggest using three groups, with the third meaning both. This value can be stored in a session variable or used when a recordset from the user table is executed on the page. Use this value in your select statement to choose records marked with the same groupID.
So you'll have three groups, 1, 2 and 3 with three indicating both. However, in the second table, the groupID in those records will still only be assigned to 1 or 2, so you'll need an OR statement in the SQL to choose both when the access level is 3.