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
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";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.