PDA

View Full Version : Having trouble with if statements



jedimastermopar
11-21-2006, 04:29 PM
I have a calulation and if the reult is zero I don't want to display anything..but here are my results. Where is the 0 comming from when the result is 0?

item2tot = 200

Statement 1
<?php if ($item2tot != '0'){ echo "value = $item2tot" ;} ?>

Output
value = 200


item2tot = 0

Statement 1
<?php if ($item2tot != '0'){ echo "value = $item2tot" ;} ?>
a 0 is displayed no value =

Output
0

jedimastermopar
11-21-2006, 04:50 PM
I think I know why it is happening.

If he user enters 0 and 0 for the two inputs, the if statment seems to work fine, If the user doens't input anything the if statement outputs a 0 I woudl assume this is refering to a NULL value or

This is where I add the two user inputs

$item2tot = floatval ($POST['item2']) * floatval ($POST['qty2']);

jedimastermopar
11-21-2006, 04:55 PM
I also tried putting in NULL instead of the '0' and I still get the same result.
I am thinking that if I can't get this to work I will have to wrap the calulation into an if NULL statement? Is that the only way to get around this?