Jump to content

WHILE loop is stopping early


emexinc

Recommended Posts

...i'm missing something, for some reason the WHILE loop is being stopped by something within the {} brackets...

 

$query = "SELECT * FROM biglist WHERE page='crown1'";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){

 

if ($row['pine'] == "y"){echo "<span class=\"w\">Pine</span> <span class=\"q\">";

$price = $item."kp";

$result = mysql_query("SELECT * FROM biglist WHERE item_number_2='$price'") or die(mysql_error());

$row = mysql_fetch_array( $result );

if ( $row == 0 ) { echo "n/a"; } else { echo "$".$row['price'];};

echo"</span>\n";};

 

if ($row['poplar'] == "y"){echo "<span class=\"w\">Poplar / P.G.</span> <span class=\"q\">";

$price = $item."p";

$result = mysql_query("SELECT * FROM biglist WHERE item_number_2='$price'") or die(mysql_error());

$row = mysql_fetch_array( $result );

if ( $row == 0 ) { echo "n/a"; } else { echo "$".$row['price'];};

echo"</span>\n";};

}

 

...now it displays a price from the first IF statement, but then it completely passes over the second iF statement, and ends the WHILE loop even though it should loop a couple more times...

 

Link to comment
https://forums.phpfreaks.com/topic/136858-while-loop-is-stopping-early/
Share on other sites

Use [ code] tags please.

 

Do these if statements only differ with this lines?

 

echo "<span class=\"w\">Pine</span>   <span class=\"q\">";
$price = $item."kp";

echo "<span class=\"w\">Poplar / P.G.</span>   <span class=\"q\">";
$price = $item."p";

 

If so, only these two lines should be inside ifs...

 

<?php
while($row = mysql_fetch_array($result)){

if ($row['pine'] == "y"){
	echo "<span class=\"w\">Pine</span>   <span class=\"q\">";
	$price = $item."kp";
} elseif ($row['poplar'] == "y"){
	echo "<span class=\"w\">Poplar / P.G.</span>   <span class=\"q\">";
	$price = $item."p";
}

$result = mysql_query("SELECT * FROM biglist WHERE item_number_2='$price'") or die(mysql_error());
$row = mysql_fetch_array( $result );
if ( $row == 0 ) { 
	echo "n/a"; 
} else { 
	echo "$".$row['price'];
}
echo"</span>\n";
}

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.