views:

30

answers:

1

I have groups on my website, and would like users to follow groups, and groups to follow users. I was wondering how does the following/follower works, in terms setting out in a MySQL table and referencing users? I'm very confused!!

A: 

The simplest way I can think of to do this is with two tables. One table is just a list of users, each with a unique userId and any other information you need to store about the user. The second table would keep track of who is following who by simply associating users by their userId. It could be just two columns, leaderId and followerId, where both columns are foreign keys to the userId in the main table.

You can then get a list of a user's followers by selecting all the rows where they are the leader.

Bill the Lizard
thanks great answer!!! but is this the effcient way to do it!! cud thier be a better way!!
getaway
@Solomon - This is the standard way to do many-to-many relationships like the one you are suggesting. There are some ways to optimize your database/tables to handle this, but you won't find a better implementation (in my opinion).
Topher Fangio
thanks for your advice!!
getaway