xoluz Posted March 17, 2006 Share Posted March 17, 2006 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 https://forums.phpfreaks.com/topic/5175-calculating-with-variables/ Share on other sites More sharing options...
kenrbnsn Posted March 17, 2006 Share Posted March 17, 2006 You need to use "==" not "=". But you said you wanted this to happen "When the '$formtotal' is more than 50 000"[code]<?phpif ($formtotal > 50000) $discount = $formtotal * 0.1;else echo 'no discount<br>';$total = $formtotal - $discount;echo 'Total: $total';?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/5175-calculating-with-variables/#findComment-18373 Share on other sites More sharing options...
xoluz Posted March 17, 2006 Author Share Posted March 17, 2006 [!--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]<?phpif ($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 https://forums.phpfreaks.com/topic/5175-calculating-with-variables/#findComment-18375 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.