Jump to content

PHP/MySQL sum() works but need sum with multiple fields


mo

Recommended Posts

Hopefully I get at least one response this time.

 

I have a query that returns the total amount of items in a shopping cart:

 

$sqlStr = mysql_query("select SUM(`price`) as total from `mr_cart`

                  WHERE `cart_session_id` = '$sid'") or die(mysql_error());

 

The table mr_cart has two fields, price and quantity. I need to get the total for each line's price * quantity.

 

Anyone???

 cart_id int(11)            

 smid int(11)          

 store_name varchar(40)          

 cart_session_id char(32)              

 cart_qty decimal(10,0)            

 price float              

 cart_date datetime            

 title varchar(40)                

 options longtext            

 comments longtext

 

I was trying to avoid doing the calculation in post processing after the query, for performance reasons. I prefer to do the sum (price * cart_qty) in the query, if possible.

 

Thanks...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.