mo Posted June 27, 2007 Share Posted June 27, 2007 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??? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 show us some table structure please, odds are it will be better to extract data raw and then total in post using arrays and a while function Quote Link to comment Share on other sites More sharing options...
per1os Posted June 27, 2007 Share Posted June 27, 2007 $sqlStr = mysql_query("select SUM(`price` * `quantity`) as total from `mr_cart` WHERE `cart_session_id` = '$sid'") or die(mysql_error()); Try that. Quote Link to comment Share on other sites More sharing options...
mo Posted June 27, 2007 Author Share Posted June 27, 2007 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... Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 27, 2007 Share Posted June 27, 2007 so i take it there is multiple rows for one cart? can you give me an example of a cart with saw 3-4 items in it. I'm not grasping this for some reason and its making me feel stupid Quote Link to comment Share on other sites More sharing options...
mo Posted June 27, 2007 Author Share Posted June 27, 2007 Thanks Frost. That did the trick, it works perfectly now. I actually thought of doing it the way you suggest but didn't even try as I thought the syntax was incorrect. I guess I was wrong. I'll experiment next time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.