LinkedIn type friends connection required in php

Posted by Akash on Stack Overflow See other posts from Stack Overflow or by Akash
Published on 2009-06-26T09:19:51Z Indexed on 2010/04/06 5:03 UTC
Read the original article Hit count: 525

Filed under:
|

Hi,

I am creating a custom social network for one of my clients.

In this I am storing the friends of a user in the form of CSV as shown below in the user table

uid    user_name      friends
1      John           2
2      Jack           3,1
3      Gary           2,4
4      Joey           3

In the above scenario if the logged in user is John and if he visits the profile page of Joey, the connection between them should appear as

John->Jack->Gary->Joey

I am able to establish the connection at level 1 i.e

If Jack visits Joey's profile I am able to establish the following :

Jack->Gary->Joey

But for the 2nd level I need to get into the same routine of for loops which I know is not the right solution + I am not able to implement that as well.

So, can someone please help me with this?

Thanks in Advance,
Akash

P:S I am not in a position to change the db architecture :(

© Stack Overflow or respective owner

Related posts about php

Related posts about algorithm