#### Archived

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

# how can i make it work ?

## Recommended Posts

hi there ! this is my firs post & i ask admins to move it if it's place isn't here (but please let me know).

let's say we have this table in our database:
[table]
[tr][td]people[/td][td]his_friend_id[/td][/tr]
[tr][td]1[/td][td]3[/td][/tr]
[tr][td]2[/td][td]1[/td][/tr]
[tr][td]1[/td][td]2[/td][/tr]
[tr][td]3[/td][td]2[/td][/tr]
[/table]

this means:
[b]row1:[/b] [i]people1[/i] has [i]people3[/i] as his friend
[b]row2:[/b] [i]people2[/i] has [i]people1[/i] as his friend
[b]row3:[/b] [i]people1[/i] has [i]people2[/i] as his friend
[b]row4:[/b] [i]people3[/i] has [i]people2[/i] as his friend

=> 1 is frend with 3 and 2
=> 2 is frend only with 1
=> 3 is frend only with 2

now.. the question is: how can i calculate the shortest road (if it exists) between 2 people ?

##### Share on other sites
Well, there's a flaw in your logic, for starters.  If 1 is friends with 3, 3 also has to be friends with 1.

To find the "shortest road", you're going to have to build relationship rules and priority.  Like, if you're trying to find out who is friends with your friends... you're going to have to do a recursive link and it's not always going to be accurate.  It will have to be smart enough to know which path to go down first and which will find the next person faster.  It'll have to be a binary tree or something similar that can traverse the entire system very quickly.

I think you'd be better off in a math/discrete math forum for something like this than asking a bunch of code monkeys.

##### Share on other sites
http://en.wikipedia.org/wiki/Six_degrees_of_separation

[quote]In the 1950s, Ithiel de Sola Pool (MIT) and Manfred Kochen (IBM) set out to prove the theory mathematically. Although they were able to phrase the question (given a set N of people, what is the probability that each member of N is connected to another member via k1, k2, k3...kn links?), after twenty years they were still unable to solve the problem to their own satisfaction.[/quote]

Have fun!!

##### Share on other sites
well .. thx but i figured it out. i have to import the database into a simetric matrix. then i'll use dijkstra's algorithm.

:-*

##### Share on other sites
[/quote]
i'm trying to make something like this: www.linkedin.com . there u can ask to see if two people are "connected". how do u think it was done?

##### Share on other sites
I went to the link as you said and looked at the website and had a play, the way the website desiner has acheved this function is using a search function.

##### Share on other sites
I went to the link as you said and looked at the website and had a play, the way the website desiner has acheved this function is using a search function.
[/quote]Thanks for that contribution redarrow...

##### Share on other sites
i am looking this up i think its a mysql function wthin mysql database seach function.

example

\$query = "select * form members_info where name like '%\$name% and age='31' and hair='blond' ";

know what i can see from my example is that all users with age 31 and hair blond should show i think not sure theo.

and therefore classed as a match example a matching dating mod to show who matches within the database

##### Share on other sites
i am looking this up i think its a mysql function wthin mysql database seach function.

example

\$query = "select * form members_info where name like '%\$name% and age='31' and hair='blond' ";

know what i can see from my example is that all users with age 31 and hair blond should show i think not sure theo.

and therefore classed as a match example a matching dating mod to show who matches within the database
[/quote]

what is the beauty of www.linkedin.com: u can make friends (much like the well knowen www.hi5.com). by adding friends, u create a network. now: if u want to find a plumber for example, this is easy. the trick isn't to find a plumber, but to see if he (the plumber) is friend with one of ur own friends.

[b]EG:[/b]

u are friend with Max, Carl and John.

John is friend with u, Max and Nick.

Nick is friend with John, Mihail and Sebastian.

Sebastian  is friend with Maria, Nick and [u][b]The Plumber[/b][/u].

and that's the beauty of it: to be able to see "the path" between u and the man u want to hire if the path exists. in our case: u, john, nick, sebastian.

this is the part i'm not so sure how to set it done :) and it couldn't be done with a search function like "\$query = "select * form members_info where name like '%\$name% and age='31' and hair='blond' ";"