Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Need to change discount on form from $20 to a percentage?
Old 05-19-2011, 03:18 PM Need to change discount on form from $20 to a percentage?
virtualgeorge's Avatar
Average Talker

Posts: 29
Trades: 0
I have a form with a field for a bonus code that gives you a $20 discount on your order.

if($promocode == 'secretcode') {;
$discount=20;
} else {
$discount=0;
};

Then I just have this to calculate the discount:
$finaltotal = $total - $discount;

So this subtracts 20 from my total but what if I wanted to make the discount 20% of the total instead of a flat $20 discount?

Do I need to create another variable something like:
$percentage = .20;

if($promocode == 'secretcode') {;
$discount= $percentage * $total;
} else {
$discount=0;
};

That didn't work so any tips appreciated.

thanks!!
virtualgeorge is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-19-2011, 03:25 PM Re: Need to change discount on form from $20 to a percentage?
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
what do you mean it didn't work? did it give an error if so what is it?
stivens is offline
Reply With Quote
View Public Profile
 
Old 05-19-2011, 03:30 PM Re: Need to change discount on form from $20 to a percentage?
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
i think it should be

$discount= $total * $percentage;
stivens is offline
Reply With Quote
View Public Profile
 
Old 05-19-2011, 03:31 PM Re: Need to change discount on form from $20 to a percentage?
virtualgeorge's Avatar
Average Talker

Posts: 29
Trades: 0
In the first working example it shows a discount of 20.
In the second example when it shows a discount of 0 but no errors.
virtualgeorge is offline
Reply With Quote
View Public Profile
 
Old 05-19-2011, 03:36 PM Re: Need to change discount on form from $20 to a percentage?
Skilled Talker

Posts: 96
Name: Joan
Trades: 0
this should work

$discount= $total * $percentage;

this will give you 0 $discount= $percentage * $total; your doing .20 * 'total' your doing it backwards
stivens is offline
Reply With Quote
View Public Profile
 
Old 05-19-2011, 03:39 PM Re: Need to change discount on form from $20 to a percentage?
virtualgeorge's Avatar
Average Talker

Posts: 29
Trades: 0
That worked, I was just calculating the discount before the total on the form so it was returning 0.

Thanks!!
virtualgeorge is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Need to change discount on form from $20 to a percentage?
 

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28706 seconds with 12 queries