Forum Moderators: coopster

Message Too Old, No Replies

Problem with calculation

php calculation

         

leonlingeehoung

2:16 pm on Jan 15, 2009 (gmt 0)

10+ Year Member



$order=mysql_query("SELECT * FROM `order`,`product` WHERE `order`.`product_id`=`product`.`product_id` AND `order`.`member_id`='$mmid' ORDER BY `product_code` ASC")or die (mysql_error());
while ($o=mysql_fetch_assoc($order))
{
$code=$o[product_code];
$pname=$o[product_name];
$pprice=$o[product_price];
$quantity=$o[quantity];
$total=$pprice * $quantity;

print '<div class="cart_result"><div class="cart_code">'.$code.'</div><div class="cart_item">'.$pname.'</div><div class="cart_price">RM '.$pprice.'</div><div class="cart_quantity"><input type="text" name="quantity" value="'.$quantity.'" size="2"></div><div class="cart_total">$ '.$total.'</div></div>';
}

print 'Total: $ ';
The output should be:

ABC Item1 10 $10
AAA Item2 20 $30
BBB Item3 5 $50

Total: $

How can I get the total from the above code? The total should be $90. I hope you can understand my question. I will appreciate who can answer my question. Thank you so much....

cameraman

2:28 pm on Jan 15, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World, leonlingeehoung.

$sum = 0;
while ($o=mysql_fetch_assoc($order))
{
$code=$o[product_code];
$pname=$o[product_name];
$pprice=$o[product_price];
$quantity=$o[quantity];
$total=$pprice * $quantity;
$sum += $total;

leonlingeehoung

2:43 pm on Jan 15, 2009 (gmt 0)

10+ Year Member



you solve my problem, thanks a lot...