Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Harsh one: How to code 3rd level friends network

12:11 pm on Feb 22, 2010 (gmt 0)

New User

5+ Year Member

joined:Dec 28, 2009
votes: 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!
6:17 pm on Feb 22, 2010 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
votes: 0

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