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!!
views:
30answers:
1
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
2010-08-30 20:46:04
thanks great answer!!! but is this the effcient way to do it!! cud thier be a better way!!
getaway
2010-08-30 20:47:44
@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
2010-08-30 20:50:01
thanks for your advice!!
getaway
2010-08-30 20:51:41