emexinc Posted December 13, 2008 Share Posted December 13, 2008 ...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... Quote Link to comment https://forums.phpfreaks.com/topic/136858-while-loop-is-stopping-early/ Share on other sites More sharing options...
Mchl Posted December 13, 2008 Share Posted December 13, 2008 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/136858-while-loop-is-stopping-early/#findComment-714799 Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2008 Share Posted December 13, 2008 Your query inside the outer loop is reusing the $result variable that the outer loop is dependent on. Quote Link to comment https://forums.phpfreaks.com/topic/136858-while-loop-is-stopping-early/#findComment-714824 Share on other sites More sharing options...
Mchl Posted December 13, 2008 Share Posted December 13, 2008 Heh... that's 100% right. Quote Link to comment https://forums.phpfreaks.com/topic/136858-while-loop-is-stopping-early/#findComment-714827 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.