spillage Posted March 19, 2008 Share Posted March 19, 2008 Hi im new to this and am reading an idiots guide to php but am stuck. i have a form with 3 items for sale. if item 1 has a value of 100 then i want to discount this by 20%. and leave the value of the others alone. i have used the if elseif to calculate different levels of discount but where would i actually remove the 20% value. i thought i could just $totalamount = $tireqty * TIREPRICE * $discount but it will not work. HOPE THIS MAKES SOME SENSE. thanks. if ($tireqty <=5) $discount=0; elseif ($tireqty >=5 && $tireqty <49) $discount=0.95; elseif ($tireqty >=50 && $tireqty<=99) $discount=0.9; elseif ($tireqty >100) $discount=0.80; $totalamount = 0.00; define('TIREPRICE', 100 ); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = $tireqty * TIREPRICE + $oilqty * OILPRICE + $sparkqty * SPARKPRICE; echo 'Subtotal: £'.number_format($totalamount,2).'<br />'; $taxrate = 0.175; // local sales tax is 17.5% $totalamount = $totalamount * (1 + $taxrate); echo 'Total including tax: £'.number_format($totalamount,2).'<br />'; Quote Link to comment https://forums.phpfreaks.com/topic/97003-reducing-total-cost-by-a-percent/ Share on other sites More sharing options...
btherl Posted March 20, 2008 Share Posted March 20, 2008 Can you try this: if ($tireqty <=5) $discount=0; elseif ($tireqty >=5 && $tireqty <49) $discount=0.95; elseif ($tireqty >=50 && $tireqty<=99) $discount=0.9; elseif ($tireqty >100) $discount=0.80; $totalamount = 0.00; define('TIREPRICE', 100 ); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = ($tireqty * TIREPRICE * $discount) + ($oilqty * OILPRICE) + ($sparkqty * SPARKPRICE); echo 'Subtotal: £'.number_format($totalamount,2).' '; $taxrate = 0.175; // local sales tax is 17.5% $totalamount = $totalamount * (1 + $taxrate); echo 'Total including tax: £'.number_format($totalamount,2).' '; What output does it give? Quote Link to comment https://forums.phpfreaks.com/topic/97003-reducing-total-cost-by-a-percent/#findComment-496485 Share on other sites More sharing options...
spillage Posted March 20, 2008 Author Share Posted March 20, 2008 thanks for the suggestion btherl I had tried just putting the $tireqty*TIREPRICE*$discount in brackets and also your way but both of these just return a zero amount. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/97003-reducing-total-cost-by-a-percent/#findComment-496592 Share on other sites More sharing options...
sasa Posted March 20, 2008 Share Posted March 20, 2008 look 1st if <?php if ($tireqty <5) $discount=1;// 1 to 4 no discount, must be 1 not 0 elseif ($tireqty <50) $discount=0.95; // 5 to 49 discount 5% elseif ($tireqty< 100) $discount=0.9; // 50 to 99 discount 10% else $discount=0.80; // 100 and more discount 20% ?> Quote Link to comment https://forums.phpfreaks.com/topic/97003-reducing-total-cost-by-a-percent/#findComment-496801 Share on other sites More sharing options...
spillage Posted March 20, 2008 Author Share Posted March 20, 2008 Thanks very much sasa all it turned out to is i had set the first $discount to 0 instead of 1. Its had me banging my head against the desk for hours. Now for chapter 2. God help me!!!! Quote Link to comment https://forums.phpfreaks.com/topic/97003-reducing-total-cost-by-a-percent/#findComment-497023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.