I have those code snippet that checks the fans table and gets everyone who has fanned you. It then checks if you have fanned them as well and if so it displays their username and profile picture.
It check if you have fanned them using $count I’m assuming this is where it’s tripping up. but firebug isn’t showing any errors.
<?php $friendlist = mysql_query("SELECT * FROM fans WHERE username='$user'") or die(mysql_error());
while($row = mysql_fetch_array($result1)) {
$friendname = $row['fanned'];
$friendlist2 = mysql_query("SELECT * FROM fans WHERE username='$friendname' AND fanned='$user'") or die(mysql_error());
$count = mysql_num_rows($friendlist2);
if($count == 1 ){
$avatar = mysql_query("SELECT * FROM users WHERE username='$friendname'") or die(mysql_error());
while($row3 = mysql_fetch_assoc($avatar)) {
$filename = $row3['avatar'];
if($filename != "") {
$friendpic = '<img id="headeravapic" src="profileavatars/' . $friendname . "/" . $filename . '" />';
}
else {
$friendpic = '<img id="headeravapic" src="images/nopic.PNG" />';
}
echo '<div align="center" id="onlinepic">' . $friendpic . '<p />' . $friendname . '</div>';
}
}
}?>
You can simplify this into one query. Something like:
If you want to restrict to ONLY those where you are mutual fans, then change the “LEFT JOIN” to an “INNER JOIN” – then you also don’t need the “YouFanThem” in the return result.
I’d also encourage you not to use “SELECT *” as it’s heavy, select just the fields you need.
Finally, the obligatory note that mysql_functions are being depreciated, so check out PDO instead.