开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜