shyam13 Posted July 20, 2012 Share Posted July 20, 2012 I have created a shopping cart and I am trying to create a line total which is automatically updated when the quantity is increased or decreased, can anyone help me with what type of query I would use? Thank You Shyam Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/ Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Depends on how you've set up your shopping cart. Do you store prices directly in the session? Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363013 Share on other sites More sharing options...
shyam13 Posted July 20, 2012 Author Share Posted July 20, 2012 I store the cost of the product directly into the $_SESSION['cart'] Thank you Shyam Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363014 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Then use array_sum, or a foreach to loop through and add the totals. Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363016 Share on other sites More sharing options...
shyam13 Posted July 20, 2012 Author Share Posted July 20, 2012 if I use this function, will the total be able to be automatically updated when the quantity is updated? Thank You Shyam Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363020 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Assuming you recalculate the total when you want to display it, yes. Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363024 Share on other sites More sharing options...
shyam13 Posted July 20, 2012 Author Share Posted July 20, 2012 yes, the total is recalculated after each quantity update. Thank You Shyam Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363026 Share on other sites More sharing options...
shyam13 Posted July 20, 2012 Author Share Posted July 20, 2012 I have tried using array_sum to recalculate the product quantity after each update, but the total is still the same, the total dosent get recalculated automatically. Thank You Shyam Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363031 Share on other sites More sharing options...
xyph Posted July 20, 2012 Share Posted July 20, 2012 Then you're doing something wrong, or your array structure makes it impossible to use array_sum on it's own. It's impossible to say, and I'm getting slightly tired of guessing solutions. You should start providing more information when you ask specific questions. Quote Link to comment https://forums.phpfreaks.com/topic/265987-line-total-for-shopping-cart/#findComment-1363061 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.