Jump to content


Photo

Calculating with variables


  • Please log in to reply
2 replies to this topic

#1 xoluz

xoluz
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 17 March 2006 - 05:58 PM

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

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

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:

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

Could someone help me out here..? :)


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 17 March 2006 - 06:05 PM

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

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

Ken

#3 xoluz

xoluz
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 17 March 2006 - 06:32 PM

[!--quoteo(post=355956:date=Mar 18 2006, 04:05 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 18 2006, 04:05 AM) View Post[/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"

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

Ken
[/quote]

Thanks! That works perfect :)

And I forgot about the ==, it should be > like you said ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users