views:

66

answers:

1

I have a user system set up in a 'users' table, and I have groups set up in a 'groups' table. Essentially, I want users to be able to join any and all the groups that they want, in the same was as one would on facebook.

How would one go about structuring this in a mysql/php database system? Just a quick summary would be helpful!

I've looked around, but I can only find info on creating 'groups' where the users just have a sort of 1, 2 or 3 permission rank.

Thanks!

+1  A: 

I would have a databse something like:

|--------|             |-------------|            |------|
| Group  | ------- 1.* | JoinedGroup | *.1------- | User |
|--------|             |-------------|            |------|

So the JoinedGroup holds a UserId and a GroupId. When a user wants to join a group just add a row to the JoinedGroup table.

Selecting users from a certain group would just require a simple inner join.

Yacoby
Yes, of course! Why didn't I think of that?
Ben C