Jump to content

IF ELSE problem


chet139

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/93904-if-else-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/93904-if-else-problem/#findComment-481181
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/93904-if-else-problem/#findComment-481182
Share on other sites

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.