I was wondering what was the best way to generate a followers list using PHP and MySQL database. So here are the two ways I have found that this can work.
Here is the first way that I have found: I can create one column for each user that will contain all of the ids of the users that they follow. When I go to retrieve the list, I explode the list of ids so that I can select all of the data from each user.
Here is what it looks like in the database:
User ID Following
1 2,3,5,6,7,9,10
5 10,5,2,20,1
The other solution that I have found is that every time a user wants to add someone to their "following" list, the database will contain 1 row just for that specific person that they are following.
User ID Following
1 2
1 5
2 1
1 42
Therefore, in the long run, I am wondering which would be the most effective way to organizing the data and retrieving data to display for the newsfeed - the easiest and least cost effective. (I already have a table that contains all of the users posts).