Jump to content

[SOLVED] Looping Once? It should loop multiple times...


pugboy

Recommended Posts

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.