// if the patron orders tickets for 4 main events // he/she receives a 10% discount on those events
function getDiscount()
{
$discResult = mysql_query ("select * from cart
inner join items
on cart.itemId = items.itemId
where cart.cookieId = '" . GetCartId() . "'
and items.itemDisc <> 'xx'
group by items.itemDisc");
$disCount = mysql_num_rows ( $discResult );
if ($disCount >= 4) {
$discPrices = mysql_query ("select * from cart
inner join items
on cart.itemId = items.itemId
where cart.cookieId = '" . GetCartId() . "'
and items.itemDisc <> 'xx'");
while ($row = mysql_fetch_array($discPrices))
$reduceBy += (($row["qty"] * $row["itemPrice"]) * 0.1);
echo number_format($reduceBy, 2);
}
else {
$reduceBy = 0;
echo number_format($reduceBy, 2);
}
}
When I call the function on the page to show the discount, everything is ok:
Subscriber Discount: $<?php echo getDiscount(); ?>
This displays "Subscriber Discount: $85.40"
I have a variable ($totalCost) which tallies the non-discounted total cost for all the tickets purchased. ($totalCost += ($row["qty"] * $row["itemPrice"]);) which works fine. I call that variable on the page like this:
Order Subtotal: $<?php echo number_format(($totalCost), 2); ?>
Which displays "Order Subtotal: $854.00"
Now here's the part that is screwy. When I try and calculate the discounted total price, using this:
$myPrice = $totalCost-getDiscount(); echo ($myPrice);
I get "8.54854" which is simply the result of the function getDiscount followed by the variable $totalCost.
Of course I expected to get the result of the equation "854 - 85.40" or "768.60"
What am I doing wrong?
Mark
-- mark hurty | mark@hurty.com | 309.764.0911
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php