I have a members table in which every site member is the unique id.
eg
id firstname secondname emailaddress country city gender
the second table is a friends table with the following structure
id meid friendid date
what query would i use to get friend suggestions of a particular user based on mutual friends and sorted accordingly. before i was using php to loop thru and collect mutual friends but as the site grew, php started misbehaving and running out of memory.
This is the function i was using
//-----------------------------------------------
function getFriendSuggestions($id)
{
$friendids=getFriendIdArray($id); //returns list of your friends
$networkids=getNetworkIdArray($id);//returns list of all members in your network(friends and their friends)
$diff=array_merge(array(),array_diff($networkids,$friendids));
$diff_mutual=array();
$diff_mutual_total=array();
for ($n=0;$n<count($diff);$n++)
{
$ff=getFriendIdArray($diff[$n]);
$mf=array_merge(array(),array_intersect($ff,$friendids));
$diff_mutual[]=$mf;
$diff_mutual_total[]=count($mf);
}
$diff=array_merge(array(),$diff);
$diff_mutual=array_merge(array(),$diff_mutual);
$diff_mutual_total=array_merge(array(),$diff_mutual_total);
$w=$diff_mutual_total;
arsort($w);
$d=array();
$dm=array();
foreach ($w as $key => $value)
{
$d[]=$diff[$key];
$dm[]=$diff_mutual[$key];
}
$cv=array($d,$dm);
return $cv;
}
You want “friends of my friends, but who are not also my friends”.