#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Adelaide, South Australia
    Posts
    15
    Rep Power
    0

    Adding the results of 2 IF statements


    Hi,

    I've got 2 IF statements that echo 2 numbers.

    I'm wondering what the easiest way to add those two numbers together and echo the total.

    I've googled around but don't seem to be able to be able to get anything to work.


    If someone could give me a hand that would be great, if you need more information just ask


    thanks
  2. #2
  3. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    108
    Rep Power
    4
    Could you post a code snippet containing the If statements?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Adelaide, South Australia
    Posts
    15
    Rep Power
    0
    Originally Posted by richpri
    Could you post a code snippet containing the If statements?
    Sure


    PHP Code:
    <?php if ($_POST['priority']=="Emergency [$45 FEE] ")   {   echo "45";   }   if ($_POST['priority']=="Emergency [$90 FEE] ")   {   echo "90";   }      ?>

    <?php
    if ($row_usersession['difftechaccount']=="NO")
      {
      echo 
    $_POST['initialhour'];  
      }  
    ?>
    Last edited by ben.y; December 31st, 2012 at 08:00 PM. Reason: typo
  6. #4
  7. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    108
    Rep Power
    4
    Try something like this.

    PHP Code:
    <?php 
    $sum 
    0;
    if (
    $_POST['priority']=="Emergency [$45 FEE] ")   {   sum += 45;   }   
    if (
    $_POST['priority']=="Emergency [$90 FEE] ")   {   sum += 90;   } 
    if (
    $sum !== 0) { echo $sum; }
    ?>
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Adelaide, South Australia
    Posts
    15
    Rep Power
    0
    Originally Posted by richpri
    Try something like this.

    PHP Code:
    <?php 
    $sum 
    0;
    if (
    $_POST['priority']=="Emergency [$45 FEE] ")   {   sum += 45;   }   
    if (
    $_POST['priority']=="Emergency [$90 FEE] ")   {   sum += 90;   } 
    if (
    $sum !== 0) { echo $sum; }
    ?>

    Sorry, I was trying to add:

    PHP Code:
    <?php if ($_POST['priority']=="Emergency [$45 FEE] ")   {   echo "45";   }   if ($_POST['priority']=="Emergency [$90 FEE] ")   {   echo "90";   }      ?>

    and


    PHP Code:
      <?php if ($row_usersession['difftechaccount']=="NO")   {   echo $_POST['initialhour'];     } ?>

    The emergency fee is only going to echo one or the other ($45 or $90) and I need to add that to $_POST['initialhour'] (which is posted from the previous page

    hope that makes sense?
  10. #6
  11. Known to taste like chicken
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    In front of my computer
    Posts
    399
    Rep Power
    312
    same concept applies. Have 1 variable to store your total and then add to it if certain conditions are met.

    PHP Code:
    <?php
    $sum 
    0;
    if (
    $_POST['priority']=="Emergency [$45 FEE] ")   {   $sum += 45;   }    
    if (
    $_POST['priority']=="Emergency [$90 FEE] ")   {   $sum += 90;   } 
    if(
    $row_usersession['difftechaccount']=="NO")   {   $sum += $_POST['initialhour'];     }
    if(
    sum != 0) { echo $sum; }
    ?>

    Comments on this post

    • richpri agrees : Yep, thats the way I would do it.
    "Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

    Looking for a project Idea?

IMN logo majestic logo threadwatch logo seochat tools logo