setting up a friend list in mysql

前端 未结 4 1778
天涯浪人
天涯浪人 2021-01-31 12:47

I want to make a friends list in my online game. I am not sure how to set it up or where to start. The add friends and accept friends part I can handle, but I don\'t know how to

4条回答
  •  醉梦人生
    2021-01-31 13:29

    A friendship is essentially a mutual relationship between two people. In database terms it's a many-to-many relationship between two users.

    So what you need is a linking table that holds references to two users by ID.

    Example

    Users table

    ID    Username
    1     Bob
    2     Jim
    3     Alice
    

    Friends table

    user1    user2
    1        2
    2        3
    

    This would make Bob friends Jim and Jim friends with Alice.

提交回复
热议问题