Jump to content

Recommended Posts

Hi,

 

I am making something where users have profiles and they can add friends.

 

The problem I am having is how to design my database for this, as one user can have many friends and all those friends can have many friends.

 

I know many to many relationships are discouraged but is that the only way this can be done?

 

I am thinking of having a column against each user where the ids of the users the user is friends with are listed i.e.

userId

userFriendIds

2

1, 13, 15, 63, 106, 253

 

So in my PHP to return all the friends of user 2, it would pull that big list of ids from the database and if stristr is true then they are friends.

 

What are your thoughts?

Link to comment
https://forums.phpfreaks.com/topic/235833-user-friends-best-way-to-do-it/
Share on other sites

P.S

 

I just thought it could be done in a different table called something like 'friendships'.

 

e.g.

userId

friendId

1

25

1

207

1

99

2

31

2

207

7

1

 

Or is this way much more inefficient, btw speed is the most important thing for me, diskspace is irrelevant.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.