I have a table called myfriends
with 2 columns:
friend_id1
friend_id2
When someone is a friend of some there will be two records. For example lets take 4 members: 1000, 1001, 1002 and 1003.
if 1000 and 1001 are friends with each other there will be two records: (1000, 1001)
and (1001, 1000)
. For the sake of the example, let's assume that 1000 is friends with 1002, as well.
I display the people who are not friends with the logged in user (For instance, 1000), and I want to display the mutual friend count next to each one. considering the example, I need to display 1 in front of 1002 and 0 in front of 1003.
This is the part of a code and the query that I use to list all the members with the add as friend button next to the name inside a table.
$query ="SELECT profile_name,friend_id from friends
WHERE friend_id<>'$friendID'
AND
friend_id NOT IN( SELECT friend_id2 from myfriends WHERE friend_id1='$friendID')";
$results = @mysqli_query($conn, $query) or die
$row = mysqli_fetch_row($results);
echo "<table width='50%' border='1'>";
while ($row) {
echo "<tr><td>{$row[0]}</td>";
?>
<td><button onclick = "window.location.href='friendadd.php?addfriend=<?php echo $row[1];?>'">Add as friend</button></td></tr>
<?php
$row = mysqli_fetch_row($results);
}
echo "</table>";
I want to display the mutual friend count of each one in between the profile name and the add as a friend button.