tescgo Posted October 28, 2010 Share Posted October 28, 2010 Hi, I am using a $_SESSION for my shopping cart but cannot figure out how to total my quantity. The format I am using is: $_SESSION['cart']['itemid']['qty'] I realise that i could write a for loop to start at item id 0 and end at 1000 each time totalling the qty field but there must be a better, more efficient way, Does anybody have any advice? Mark Quote Link to comment Share on other sites More sharing options...
pengu Posted October 28, 2010 Share Posted October 28, 2010 You could use the ITEM_ID and an SQL query. SELECT sum(qty) FROM items WHERE itemid = $_SESSION['itemid'] Or am I way off here? Quote Link to comment Share on other sites More sharing options...
btherl Posted October 29, 2010 Share Posted October 29, 2010 You could store the total in the session as well, and update it only when the cart contents and/or their prices/quantities change. That's more efficient than calculating it every 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.