chet139 Posted March 1, 2008 Share Posted March 1, 2008 I have the following code which works as desired. $sql="select * from product"; $result = @mysql_query($sql);//runs query while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $productId = $row['productId']; $qty = $row['stockQuantity']; $reorder = $row['reOrderlevel']; $make = $row['productMake']; $model = $row['productModel']; if ($qty <= $reorder) { echo '<blink><b><font color="red">Stock Alert</font></b></blink><br/>'; echo '**The stock level for Product <b>[' .$productId . '] '.$make.' '.$model.'</b> is low. A reorder maybe required.**<br/><br/>'; } } It basically gets information from product table compares the variable and echos if required. What I tried to do with the bit of modified code below is is all stock issues are ok (ie if no current stock levels are = to or < then minimum amount then output OK. $sql="select * from product"; $result = @mysql_query($sql);//runs query $stockProblem = false; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $productId = $row['productId']; $qty = $row['stockQuantity']; $reorder = $row['reOrderlevel']; $make = $row['productMake']; $model = $row['productModel']; if ($qty <= $reorder) { $stockProblem= true; echo '<blink><b><font color="red">Stock Alert</font></b></blink><br/>'; echo '**The stock level for Product <b>[' .$productId . '] '.$make.' '.$model.'</b> is low. A reorder maybe required.**<br/><br/>'; } } if ($stockProblem = false) { echo"Stock Levels OK"; } But if there are no problems ie stockProblem = false, then it does not output anything... any idea whats wrong...maybe its my logic?? i also tried if ($stockProblem == false) - then it just displays all the time... Quote Link to comment Share on other sites More sharing options...
QuietWhistler Posted March 1, 2008 Share Posted March 1, 2008 First of all, = is different than ==. The = operator, is the assignment operator and you use it like this: $variable = "value"; the == is a comparison operator and it is used for checking/comparing variables. So your if statement should be: if( $stocbProblem == false ){ //rest } Then, if it runs everytime, try outputting the $reorder and $qty values to check whether $stockProblem is actually set to true. Quote Link to comment Share on other sites More sharing options...
chet139 Posted March 1, 2008 Author Share Posted March 1, 2008 I was close here working code: $stockProblem = false; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $productId = $row['productId']; $qty = $row['stockQuantity']; $reorder = $row['reOrderlevel']; $make = $row['productMake']; $model = $row['productModel']; if ($qty <= $reorder) { $stockProblem= true; echo '<blink><b><font color="red">Stock Alert</font></b></blink><br/>'; echo '**The stock level for Product <b>[' .$productId . '] '.$make.' '.$model.'</b> is low. A reorder maybe required.**<br/><br/>'; } } if ($stockProblem == false) { echo"Stock Levels OK"; } [sOLVED] Thanks! Quote Link to comment 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.