Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Having trouble with if statements

    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

  • #2
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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']);

  • #3
    Regular Coder
    Join Date
    Nov 2006
    Posts
    106
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •