homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

Harsh one: How to code 3rd level friends network

5+ Year Member

Msg#: 4084707 posted 12:11 pm on Feb 22, 2010 (gmt 0)

I am building a business networking site. Each user will have own network of contacts, like on LinkedIn. So there will be his direct contacts (1st level), contacts of his contacts (2nd level) and 3rd level contacts.

I am not sure what would be the best way to get information about entire user network to 3rd degree level.

I have tried many things:
-I created for each friend connection a new row in mysql database (id | userid | friendid). Than did query SELECT * FROM network WHERE userid=$userid, than with PHP while loop and query for each friend to get all contacts of user friends and than again the same to get 3rd level.
-all 1st level friends in 1 field as text (separate them with : and than use PHP explode). Than do similar same to get 2nd and 3rd level.
-again for each 1st level friend connection a separated row but all 2nd and 3rd contacts into 1 field as text (id | userid | friendid | networkoffriend (separate 2nd level with ":" and 3rd level with ";" ).

All options are far too slow. I have no idea how LinkedIn, Xing and other business social networking sites are doing this because if each user has 100 friends than there is 1mio users in 3rd level.

Has anybody any idea?

Thanks a lot!



WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4084707 posted 6:17 pm on Feb 22, 2010 (gmt 0)

Welcome aboard meee. Recently discussed, Heriarchial Data Structures [dev.mysql.com] should be of some use to you.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved