Social Network Feature - Add Friend

Discussion in 'MySQL' started by timallard, Sep 27, 2008.

  1. #1
    Hello,

    im trying to create a niche social network. Im working on the "add a friend" part an im not sure how to go about doing this. im using MySQL and PHP

    I have a table users and there is a userId primary key.
    I want a user to be able to add friends, what do i need to create for the user to store friend info?...and how do they associate another?

    Thanks!
     
    timallard, Sep 27, 2008 IP
  2. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #2
    You need to establish a user -> friend relationship using a link (association) table. It can be as simple as creating a User_Friend table as follows:

    User Table
    UserRecID
    FirstName
    LastName
    etc.

    User_Friend Table
    UserRecID
    FriendRecID

    User Table
    1, Fred, Smith
    2, John, Doe
    3, Sarah, Davis
    4, Kim, Jones

    User_Friend Table
    1,2 (Fred has friend John Doe)
    1,4 (Fred has friend Kim Jones)
    4,2 (Kim has friend Jone Doe)
    etc.

    I should note that this may or may not meet your requirements, but wanted to give you something to think about. Good luck.
     
    Social.Network, Sep 28, 2008 IP
    timallard likes this.
  3. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #3
    Thanks for your reply, It makes sense, I will try and let you know how it goes. Either way +rep. thanks!
     
    timallard, Sep 29, 2008 IP