i want to display the quantity of products user had selected to purchased but
i had a shopping cart in which there are many products. user can purchase any number of specific item or different items e.g. he buys 3 items of product number 1, and he buys 2 items of product number 2.
This is stored in database as two different records for single user with his id. Now when i want to see totall number of items he has selected.
how can开发者_运维知识库 i do that ?
You can sum the quantity for each row that user has:
SELECT SUM(ItemQuantity) FROM CART WHERE USERID = X
with a sql query. look
SELECT SUM(items) AS 'total' FROM basket WHERE user_id = ? GROUP BY user_id
You need to pull all the records from the database for that id and purchase date and then combine the relevant columns using some basic maths.
精彩评论