<?php
$sun=mysql_query("SELECT * FROM `red_users` WHERE `role`='user' AND `userID` != '$userID' ORDER BY `id` DESC LIMIT 10 ") or die(mysql_error());
while($su[]=mysql_fetch_array($sun)){
}
for($i=0;$i<count($su);$i++){
$sud=$su[$i]['userID'];
$sname=$su[$i]['name'];
$dop=$su[$i]['dp'];
$sxx=$su[$i]['sex'];
if($dop != ''){
$sey=$dop;
}
if($dop =='' AND $sxx=='MALE'){
$sey="../images/male.png";
}
if($dop =='' AND $sxx=='FEMALE'){
$sey="../images/female.png";
}
?>
<a href="profile.php?frnd=<?php echo $sud ?>">
<div class="inbox-item">
<div class="inbox-item-img"><img src="<?php echo $sey ?>" class="img-circle" alt=""></div>
<p class="inbox-item-author"><?php echo $sname; ?></p>
</div>
</a>
<?php } ?
In output an extra Html element (with no dynamic data) is displaying.
After the Real elements which are populated by mysql query an extra element is displaying which contain no data.
Instead of
while($su[]=mysql_fetch_array($sun)){
}
and further processing of $su
process every record in the same while
:
while($su=mysql_fetch_array($sun)){
// do stuff
}
Additional note by @mloureiro:
This because the while
keeps running till it find a false
value, so when the mysql_fetch_array
doesn't have anything else to return, it will give false
that will be passed to the $su[]
array.