Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

multiple users need to see some documents in SQL table, PHP

New Here ,
Sep 02, 2011 Sep 02, 2011

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,

TOPICS
Server side applications

Views

406
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 02, 2011 Sep 02, 2011

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 03, 2011 Sep 03, 2011

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

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Sep 03, 2011 Sep 03, 2011

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines