php - Query is not getting all mysql_fetch_assocs's -



php - Query is not getting all mysql_fetch_assocs's -

could tell me why next bit of code gets images in query except last?

$userquery = mysql_query("select * acceptedfriends profilename='$profilename' order rand() limit 4"); while ($userrun = mysql_fetch_assoc($userquery)) { $users = $userrun['username']; $imagequery = mysql_query("select * users2 username='$users'"); while ($imagefetch = mysql_fetch_assoc($imagequery)) { $location = $imagefetch['imagelocation']; $image = "<img src='$location' width='60' height='40'>"; if ($profilename==$username) { echo '<div id="hovercolor2" style="width:294px; float:left;"><table><tr> <td>'.$image.'</td><td><div style="margin-bottom:5px;"><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></div><div><a href="http://www.pearlsquirrel.com/conversation.php/'.$users.'" style="text-decoration:underline;" target="_blank"><div style="font-size:.7em";>click come in conversation.</div></a></div></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>'; } else { echo '<div id="hovercolor2" style="width:294px; float:left;"><table><tr><td>'.$image.'</td><td><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>'; } } }

this

$image = "<img src='$location' width='60' height='40'>";

is not getting lastly image in query. have spend , hr trying solve , have no idea. help appreciated.

simplified code same error

$userquery = mysql_query("select * acceptedfriends profilename='$profilename' order id desc limit 6"); while ($userrun = mysql_fetch_assoc($userquery)) { $users = $userrun['username']; $location = $userrun['imagelocation']; $image = "<img src='$location' style='width:60px; height:40px;'>"; if ($profilename==$username) { echo '<div id="hovercolor2" style="width:294px; float:left;"><table><tr><td>'.$image.'</td><td><div style="margin-bottom:5px;"><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></div><div><a href="http://www.pearlsquirrel.com/conversation.php/'.$pageusers.'" style="text-decoration:underline;" target="_blank"><div style="font-size:.7em";>click come in conversation.</div></a></div></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>'; } else { echo '<div id="hovercolor2" style="width:294px; float:left;"><table><tr><td>'.$image.'</td><td><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>'; } }

what happens when run print_r(mysql_fetch_assoc($userquery)); on both select statements? see info in array? i'm assuming doing limit 4 on purpose? don't run while loop within of another, can seek instead:

$userquery = mysql_query("select * acceptedfriends profilename='$profilename' order rand() limit 4"); while ($userrun = mysql_fetch_assoc($userquery)) { $userarray[] = $userrun; } print_r($userarray); echo '<br /><br />'; foreach ($userarray $uservalue) { $users = $uservalue['username']; $imagequery = mysql_query('select * users2 username="'.$users.'"'); while ($imagefetch = mysql_fetch_assoc($imagequery)) { //echo out variables above select create sure you're getting them $location = $imagefetch['imagelocation']; $image = "<img src='$location' width='60' height='40' />"; if ($profilename==$username) { echo '<div id="hovercolor2" style="width:294px; float:left;"><table><tr> <td>'.$image.'</td><td><div style="margin-bottom:5px;"><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></div><div><a href="http://www.pearlsquirrel.com/conversation.php/'.$users.'" style="text-decoration:underline;" target="_blank"><div style="font-size:.7em";>click come in conversation.</div></a></div></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>'; } else { echo '<div id="hovercolor2" style="width:294px; float:left;"><table><tr><td>'.$image.'</td><td><a href="http://www.pearlsquirrel.com/'.$users.'" target="_blank">'.$users.'</a></td></tr></table></div><div id="hrdiv3" style="float:left; width:298px;"></div>'; } } }

make sure debug checking values exist when querying script. hope helps

php

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -