Jump to content

Recommended Posts

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 />';

Link to comment
https://forums.phpfreaks.com/topic/97003-reducing-total-cost-by-a-percent/
Share on other sites

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?

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%
?>

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.