Jump to content

User Friends, best way to do it?


imperium2335

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.