简体   繁体   中英

Assigning group membership to users from Mysql database using PHP

enter image description here

Users table

Id username  firstname  lastname
1  pmartin   Paul   Martin
2  pnorton   Peter  Norton
3  ladams    Lee    Adams

Group_membership table

Id  Group
1   Administrators
2   Developers
3   Technicians

Help is needed. I have registered users in Mysql database users table. These users can logon to the system with their username. From a different web page, I want to assign group membership to each registered users by using PHP and MySQL. I do not know how I can achieve this.

Exemple;

Users        group_membership
pmartin  ->  Administrators, Developers
pnorton  ->  Technicians
ladams   ->  Developers, Technicians

Since, there is a many to many relationship here, create a new table to map user ids with membership id

user_membership
----------------
id              - PK
user_id         - foreign key referencing Users.id
membership_id   - foreign key referencing Group_membership.id

and use joins later to get the relevant details.

Do not be tempted to store multiple values in one row as CSV. Normalization is your friend.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM