tags:

views:

62

answers:

4

I want to create a group function on my site and I'm wondering what the best way to do this would be? would i be best to create two tables groups and group_members? im fairly new to sql so im not so sure.

im thinking this:

groups
  group_id int(11) NOT NULL auto_increment,
  group_name varchar(32) NOT NULL
group_members
  id int(11) NOT NULL auto_increment,
  group_id int(11) NOT NULL
  user_id int(11) NOT NULL
users
  id int(11) NOT NULL auto_increment
  username varchar(24) NOT NULL
  password varchar(32) NOT NULL

would that be the best? or is there a better way?

Cheers boys

EDIT: CHECK MY LAST MESSAGE FOR ANOTHER QUESTION :)

+1  A: 

would that be the best?

Exactly.

It's a many-to-many relationship.

Quassnoi
+1  A: 

That is how I would do it.

Another option would be to put a group_id column in the users table, but if you do that you'd be restricting yourself to only one group per user. The way you are doing it allows a many to many relationship, which I think is the best route to go :o)

Tina Orooji
A: 

ok thats what im gonna do then guys. nice site this is btw fast answers :D

thanks

A: 

another question in the same area...buddy function? how should i structure that?

something like this?

friends
  friendid_1 int(11)
  friendid_2 int(11)
  accepted enum('1','0') default '0'

but then both users have to send a friend invite? lets say user1 sends user2 a friend request and user2 accept then it will show up on user1's profile...maybe you could make an if clause but im not sure if thats the best...what would you do?