I am working on a social networking feature's site which has a section like facebook PEOPLE YOU MAY KNOW that consists the person who are not friends of logged in user.
TABLE 1 'users' structure: uid(primary), fname, lname, dob, etc.
TABLE 2 'friend_request' structure: id(primary) uid, fid, created
TABLE 3 'friends' structure: same as 'friend_request'
I want to show people other than logged in user and his/her friends.Because i want to keep it simple.
MYSQL query is below:
<?php
/*
section for displaying random person who are not friends.
*/
$q =mysql_query("select * from users where uid!='".$_SESSION["logged"]."'");
if(mysql_num_rows($q)>0)
{
while($fetch=mysql_fetch_array($q))
{
$sel=mysql_query("select * from friends where (uid='".$fetch["uid"]."' and
fid!='".$_SESSION["logged"]."') or
(uid!='".$_SESSION["logged"]."' and fid='".$fetch["uid"]."')") or
die(mysql_error());
$num_rows=mysql_num_rows($sel);
if($num_rows>0)
{
while($rows=mysql_fetch_array($sel))
{
$que=mysql_query("select * from users where uid='".$rows['uid']."' or
uid='".$rows['fid']."'");
if(mysql_num_rows($que)>0)
{
while($names=mysql_fetch_array($que))
{
?>
<li><a href="user_index1.php?id=<?php echo $names['uid']; ?>"><strong>
<?php echo $names['fname']." ".$names['lname'] ?></strong></a></li>
<?php }
}
}
}
}
}
?>