PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 31st, 2012, 06:53 PM
ben.y ben.y is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Adelaide, South Australia
Posts: 13 ben.y User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 46 m 24 sec
Reputation 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

Reply With Quote
  #2  
Old December 31st, 2012, 06:57 PM
richpri's Avatar
richpri richpri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Chicago
Posts: 49 richpri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 32 m 9 sec
Reputation Power: 1
Facebook
Could you post a code snippet containing the If statements?

Reply With Quote
  #3  
Old December 31st, 2012, 06:59 PM
ben.y ben.y is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Adelaide, South Australia
Posts: 13 ben.y User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 46 m 24 sec
Reputation Power: 0
Quote:
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 07:00 PM. Reason: typo

Reply With Quote
  #4  
Old December 31st, 2012, 07:29 PM
richpri's Avatar
richpri richpri is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Chicago
Posts: 49 richpri User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 32 m 9 sec
Reputation Power: 1
Facebook
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; }
?>

Reply With Quote
  #5  
Old December 31st, 2012, 07:42 PM
ben.y ben.y is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Adelaide, South Australia
Posts: 13 ben.y User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 46 m 24 sec
Reputation Power: 0
Quote:
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?

Reply With Quote
  #6  
Old December 31st, 2012, 09:04 PM
sir_drinxalot's Avatar
sir_drinxalot sir_drinxalot is offline
Known to taste like chicken
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Location: In front of my computer
Posts: 377 sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level)sir_drinxalot User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 3 h 27 m 44 sec
Reputation Power: 293
Send a message via MSN to sir_drinxalot
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?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Adding the results of 2 IF statements

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap