LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-20-2005, 05:13 AM   #1
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Rep: Reputation: 30
Math operations with PHP


<?
echo '

Your Sub Total is:

' . $_POST['sub_tot'] . '

';

$msg .= "\nSub Total: $" . $_POST['sub_tot'] . "\n";

;?>


Hello folks,
How can I tune this code to make more calculations?
Say, if ' . $_POST['sub_tot'] . ' is bigger than 200,
subtract 10% from it, and print the result.
If it is bigger than 300 deduct 15% and print the result.
Thanks in advance.
 
Old 04-20-2005, 06:58 AM   #2
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
$first = 154;
$second = 254;
$third = 354;

$subtot1 = $_POST['sub_tot'];
$percentage_1 = 0.10;
$discount_1 = $subtot1 * $percentage_1 -$subtot1;

$subtot2 = $_POST['sub_tot'];
$percentage_2 = 0.15;
$discount_2 = $subtot2 * $percentage_2 -$subtot2;



THis is very clamsy, but...

if ($subtot1 >= $first) {
echo "Your discount is 10% - Total: $discount_1";
} elseif ($subtot2 >= $second) {
echo "Your discount is 15% - Total: $discount_2";
}


Unfortunately, the first statement is always true. If $subtot1 is greater than 154, it always print "Your disocunt is 10%

How can I tell the script
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++:Operations with iterators frankie_DJ Programming 12 10-20-2005 03:39 AM
Unchecked or unsafe operations???? KissDaFeetOfSean Programming 1 09-12-2005 04:06 PM
file operations in BASH snorky Linux - Newbie 2 11-24-2003 07:07 PM
Aritmethical operations davi_cabral Linux - Newbie 1 09-26-2003 11:04 AM
Modem operations dbeyes Linux - Newbie 1 04-22-2003 06:09 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration