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 Link to comment https://forums.phpfreaks.com/topic/217157-_session-shopping-cart-problem/ 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? Link to comment https://forums.phpfreaks.com/topic/217157-_session-shopping-cart-problem/#findComment-1127804 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. Link to comment https://forums.phpfreaks.com/topic/217157-_session-shopping-cart-problem/#findComment-1127842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.