Jump to content

Calculating with variables


xoluz

Recommended Posts

Hi was wondering something, I've got the following code now:

[code]
$ruletotal = $array['amount'] * $array['price'];
$formtotal = array_sum($ruletotal)
[/code]

This thing works imo, but now I want to add something to it. When the '$formtotal' is more than 50 000, I want to calculate 10% of it. So i got this added, but something isn't working:

[code]
if ($formtotal = 50000) {
$discount = $formtotal /100*10; }
else { echo 'no discount';}
$total = $formtotal - $discount;
echo 'Total: $total';
[/code]

Could someone help me out here..? :)
Link to comment
Share on other sites

You need to use "==" not "=". But you said you wanted this to happen "When the '$formtotal' is more than 50 000"

[code]<?php
if ($formtotal > 50000)
     $discount = $formtotal * 0.1;
else
     echo 'no discount<br>';
$total = $formtotal - $discount;
echo 'Total: $total';
?>[/code]

Ken
Link to comment
Share on other sites

[!--quoteo(post=355956:date=Mar 18 2006, 04:05 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 18 2006, 04:05 AM) [snapback]355956[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You need to use "==" not "=". But you said you wanted this to happen "When the '$formtotal' is more than 50 000"

[code]<?php
if ($formtotal > 50000)
     $discount = $formtotal * 0.1;
else
     echo 'no discount<br>';
$total = $formtotal - $discount;
echo 'Total: $total';
?>[/code]

Ken
[/quote]

Thanks! That works perfect :)

And I forgot about the ==, it should be > like you said ;)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.