[thelist] PHP Doubling up

Jay Blanchard jay.blanchard at niicommunications.com
Wed Aug 14 08:39:01 CDT 2002


[snip]
/* Lets get the total of products and the total cost */
function status($cart) {
	if($cart) {
		foreach ($cart as $item => $value) {
			$number += $cart[$item][qty];
			$total += $total + ($cart[$item][qty] * $cart[$item][unit_price]);
		}
		$total = correct($total);
		$return = "Your order contains <strong>".$number." </strong>";
        $return .= "items costing a total of
<strong>&pound;".$total."</strong>";
	}

	return($return);
}
[/snip]

At first blush this appears to be ok, so is the quantity for the first item
'2' or '1'? Insert a print statement to print out your key/value pairs and
see what is going on there first. If the quantity of the first item is '1'
then the problem is within this code, if it is not '1' then we'll have to
look beyond here.

HTH!

Jay





More information about the thelist mailing list