Search code examples
phpsocial-networkingmysql

How to implement followers for users, as in twitter


I have a social network that I am making using php and mysql. I am trying to figure out how to make followers for each user. Should I create a table in mysql with a list of followers for each person, and create a table for everybody they follow? How should this work? How should I set up my data structures? Please help.


Solution

  • Table `followers`
    
    id
    user_id
    follows_id
    

    If a user follows another, add their ids to this table where user_id is the user that follows and follows_id is the user he's following.