need help with discounting prices

I am trying to write an elseif statement that will discount an items price by a percentage amount based on the number of items purchased. I’ve got the everything else working except the discount. Here is the discount part:

[php]
$discount = (???);

if ($tireqty < 3) {
$discount = 0;
} elseif (($tireqty >= 4) && ($tireqty <= 7)) {
$discount = 5;
} elseif (($tireqty >= 8) && ($tireqty <= 11)) {
$discount = 10;
} elseif ($tireqty >= 12) {
$discount = 15;
}
[/PHP]

I take it the numbers you produce for discount are percentages?

[php]$tireqty = 10;

$price = 10;
$discount = 0;

if ($tireqty < 3) {
$discount = 0;
} elseif (($tireqty >= 4) && ($tireqty <= 7)) {
$discount = 5;
} elseif (($tireqty >= 8) && ($tireqty <= 11)) {
$discount = 10;
} elseif ($tireqty >= 12) {
$discount = 15;
}

$price = ($price / 100) * (100 - $discount);

echo $price;[/php]

Try it out at: http://codepad.org/FO5lrxAz

Sponsor our Newsletter | Privacy Policy | Terms of Service