Show only those who are mutual friends?

Good afternoon there is a block to show a random potential friends , but it would be better to show those with whom you have mutual friends how you can implement ?

the fields in the table

5a718fc2283c0641584753.png

Output function possible friends

function relationship_suggest($limit, $refId = null, $only_people = true) {
 $ignoredUsers = mostIgnoredUsers();
 $refId = ($refId) ? $refId : get_userid();

 $whereClause = "";

 $ignoredUsers = array_merge($ignoredUsers, get_friends($refId));
 $ignoredUsers = array_merge($ignoredUsers, get_requested_friends($refId));
 $friendsFriends = get_friends_of_friend($refId);
 if ($friendsFriends) {
 $friendsFriends = implode(',', $friendsFriends);
 $whereClause .= "id IN({$friendsFriends}) ";
}

 //$followersFollowing = get_following_following($refId);
 $ignoredUsers = array_merge($ignoredUsers, get_following($refId));

 $userCountry = get_user_data('country');
 $userCity = get_user_data('city');
 $userState = get_user_data('state');
 $whereClause .= ($whereClause) ? "OR `country`='{$userCountry}' OR `city`='{$userCity}' OR `state`='{$userState}' OR avatar !="": "`country`='{$userCountry}' OR `city`='{$userCity}' OR `state`='{$userState}' OR avatar !="";
 $whereClause = fire_hook('users.suggestion.sql', $whereClause);
 $after_whereClause = "";
 $after_whereClause = fire_hook('users.category.filter',$after_whereClause,array($after_whereClause, true));
 $ignoredUsers = implode(',', array_merge(array($refId), $ignoredUsers));
 $mutual = array();
 $loggedInFriends = get_friends();
 $userid = get_userid();
 $thisUserFriends = get_friends($userid);
 if (is_array($thisUserFriends)) {
 foreach($thisUserFriends as $f) {
 if (in_array($f, $loggedInFriends) and $f != get_userid()) $mutual[] = $f;
}
}
 $fields = get_users_fields();


 $query = "SELECT {$fields} FROM `users` WHERE `ID NOT IN({$refId}) AND ({$whereClause}) AND id NOT IN ({$ignoredUsers}) AND activated=1 {$after_whereClause} ORDER BY rand()";
 $query = fire_hook("state.city.suggestions",$query,array($fields,$refId,$whereClause,$ignoredUsers));
if($only_people){

 $query = fire_hook('get.suggest.non.doctors',$query,array($fields,$mutual,$refId,$whereClause,$ignoredUsers));
}
//exit($query);
 return paginate($query, $limit);
}


There is a function shows only the number of common friends
get_mutual_friends function($userid) {
 $loggedInFriends = get_friends();
 $thisUserFriends = get_friends($userid);
 $mutual = array();
 if (is_array($thisUserFriends)) {
 foreach($thisUserFriends as $f) {
 if (in_array($f, $loggedInFriends) and $f != get_userid()) $mutual[] = $f;
}
}
 return $mutual;
}
June 8th 19 at 17:28
1 answer
June 8th 19 at 17:30
with whom you have mutual friends how you can implement

Sample of table of friends and again join the same table ("friends of friends"). And after all adjustments, the total city and so on.

Find more questions by tags PHPSQL