I have the following tables
users: uid, name_f, name_l...
group_data: id, group_id, admin, invitedusers, subscribers...
When user, ‘uid:4’ for example creates a group and invites his friends ‘uid:7′ and uid:9’ I insert into the group_data table:
'admin:4, invitedusers:4,7,9, subscribers:4,7,9'. I
If for example uid:9 doesn’t want to receive notifications, I simply remove him/her from the comma-delimited list, subscribers to make it 'subscribers:4,7' I also do the same when an admin removes a user from the group except I alter the invitedusers column.
I understand that this setup is extremely flawed and that I have to create a new table for invitedusers and subscribers. I’m just looking for a way to create that table and also an sql query that selects all users in the new system.
Any help is wonderfully appreciated. Also, this answer somewhat touched on the subject but I don’t quite understand the structure reference and couldn’t implement it: SQL Array Search
You should have one table with one row for each user that exists, like you already do. Call it ‘users’. This table will have only the information about the user, not which groups they are in.
You should have another table with one row for each group, which you do. Call it ‘groups’. This table will have only the information about the group, not who is in it.
You should have a third table with one row for each user for each group they’re in. Call it ‘user_groups’ or something. Each row in this table will link one user from the ‘users’ table to one group from the ‘groups’ table, and possibly give information about their subscription to that group.
A sample setup may look like:
EDIT Answering question from comments: