Mark
On Tuesday, May 13, 2003, at 01:48 PM, Matt Schroebel wrote:
I don't see a return $reduceBy; in the function getDiscount
-----Original Message----- From: mark hurty [mailto:hurty@mac.com] Sent: Tuesday, May 13, 2003 12:58 PM To: php-db@lists.php.net Subject: wierd math problem
It could be that I was just up too late and I'm not seeing something really obvious, but I having a weird math problem. in my script I have a function which calculates a discount for the purchase of tickets to a chamber music festival. Here's the function which performs as expected:
cart.itemId = items.itemId// 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 onwherecart.cookieId = '" .items.itemDisc <> 'xx'");GetCartId() . "' andwhile ($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
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
-- 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