pugboy Posted July 10, 2008 Share Posted July 10, 2008 For some reason, my while statement is only looping once regardless of how many orders are in the table... $q = "SELECT * FROM orders"; $result = mysql_query($q); while($row = mysql_fetch_array( $result )) { $id = $row["shop"]; $oid = $row["id"]; $iid = $row["iid"]; $username = $row["user"]; $status = $row["status"]; $q = "SELECT name FROM store" . $sid . " WHERE id = '" . $iid . "'"; $result = mysql_query($q); list($item) = mysql_fetch_array($result); $price = $row["price"]; if($row["currency"]=="gg") $price = $price . " GG"; else $price = $price . " FFCG"; if($sid==$id) echo "<tr><td class='style1'>$oid</td><td class='style2'>$username</td><td class='style2'>$item</td><td class='style2'>$price</td><td class='style2'>$status</td><td class='style2'>$custom</td></tr>"; } $row["shop"] is the shop ID that the order is for (OID), and IID is the Item ID... So if the current shop you are logged in for ($sid) is equal to the order shop ID (it belongs to you), it should display... It only loops once, why? Link to comment https://forums.phpfreaks.com/topic/114177-solved-looping-once-it-should-loop-multiple-times/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 10, 2008 Share Posted July 10, 2008 Because you are reusing $result inside of the loop so it no longer holds the correct value when the while() statement is evaluated the second time. Be careful to not change variables that loops are using. Edit: I would guess that php is generating an error as well that would have helped pinpoint the problem. When learning php, developing php code, or debugging php code turn on full php error reporting to get php to help you with problems like this one. Link to comment https://forums.phpfreaks.com/topic/114177-solved-looping-once-it-should-loop-multiple-times/#findComment-587066 Share on other sites More sharing options...
pugboy Posted July 10, 2008 Author Share Posted July 10, 2008 Oh, I am a moron XD Link to comment https://forums.phpfreaks.com/topic/114177-solved-looping-once-it-should-loop-multiple-times/#findComment-587069 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.