hi everyone!
i`m trying to display a friend of a friend from a friend table,but i dont know how to do it.
i have a table called friends,which has id,friendid and userid fields.
Now i want if a member loggin, to be displayed a list of friends of his friends which are not his friends.
i hope u u got me guys!i`m hopping to hear frm You.
below is what i tried to but it gave me infinite datas.
<?php
//Connect to the database server
include"config.php";
$user=$_SESSION['user'];
$logged_id=$_SESSION['id'];
//select all your friends
$select=mysql_query("SELECT *FROM friends WHERE userid='$logged_id' ORDER BY RAND() LIMIT 2");
$count_friends=mysql_num_rows($select);
if($count_friends>0){
while($r=mysql_fetch_array($select)){
$friendid=$r['friendid'];
//select friends of a friend except yourself and which ar not ur friends
$sqr=mysql_query("SELECT *FROM friends WHERE ((userid='$friendid') and (((userid !='$logged_id') or (friendid !='$friendid')) or (userid !='$friendid') or (friendid !='$logged_id')))");
while($raw=mysql_fetch_array($sqr)){
$friendoffriend=$raw['friendid'];
$_query = mysql_query("SELECT * FROM profile WHERE id = '$friendoffriend'");
$_row = mysql_fetch_array($_query);
$name=$_row['names'];
echo"$name fomt";
}
}
}else{
echo"You must add friends";
}
?>