TheDudeAp Posted September 11, 2009 Share Posted September 11, 2009 Hey guys, I am programming a social networking site and I'm programming the system to have friends. The only want I can think of to do this is under each record in the table "user" I have a column called "friends" and I populate this comma delimted and then search through all the "friends" when I need to. I'm just worried that when people start getting 1000+ friends the system is going to crash. Think there is a better way to do this? Thanks in advance, Dan Link to comment https://forums.phpfreaks.com/topic/173892-programming-friends-on-a-social-networking-site/ Share on other sites More sharing options...
cbolson Posted September 11, 2009 Share Posted September 11, 2009 Hi, I would suggest that you have a sperate table that simply holds friend ids linking the two together: id user_id friend_id You simply add a new row for each friend (you might want to add a date_add "date" column so that you know how long they have been friends for) This might mean you having a large table as regards number of rows but shouldn't be a problem perfomance wise and will be far easier to use. Chris Link to comment https://forums.phpfreaks.com/topic/173892-programming-friends-on-a-social-networking-site/#findComment-916655 Share on other sites More sharing options...
jonniejoejonson Posted September 11, 2009 Share Posted September 11, 2009 I would have a seperate table called friends. store both the users user_Id and the user_Id of the friend. Link to comment https://forums.phpfreaks.com/topic/173892-programming-friends-on-a-social-networking-site/#findComment-916657 Share on other sites More sharing options...
Mark1inLA Posted September 11, 2009 Share Posted September 11, 2009 Hey guys, I am programming a social networking site and I'm programming the system to have friends. The only want I can think of to do this is under each record in the table "user" I have a column called "friends" and I populate this comma delimted and then search through all the "friends" when I need to. I'm just worried that when people start getting 1000+ friends the system is going to crash. Think there is a better way to do this? Thanks in advance, Dan Like other people mentioned, an intermediate table between users & friends should solve your problem. The anti-pattern sticky thread has a very good explanation of this along with a bunch other helpful 'did you knows'. Link to comment https://forums.phpfreaks.com/topic/173892-programming-friends-on-a-social-networking-site/#findComment-916808 Share on other sites More sharing options...
Mark1inLA Posted September 11, 2009 Share Posted September 11, 2009 Hi, I would suggest that you have a sperate table that simply holds friend ids linking the two together: id user_id friend_id You simply add a new row for each friend (you might want to add a date_add "date" column so that you know how long they have been friends for) This might mean you having a large table as regards number of rows but shouldn't be a problem perfomance wise and will be far easier to use. Chris Just an FYI from my experience, the id wouldn't be necessary for this table. The index can be (user_id, friend_id). Link to comment https://forums.phpfreaks.com/topic/173892-programming-friends-on-a-social-networking-site/#findComment-916820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.