Calculate a shopping cart algorithm. after a customer adds a product to the shopping cart for purchase, how can he get the total price of the product? for example, the unit price of Apple is 10 RMB; 5 RMB, 8 RMB for dragon fruit, 3 Apple, 2 bananas, and 5 dragon fruit. Currently, the database is designed like this & nbsp; a table with id and product name, price, put id in Table B (calculate a shopping cart algorithm relative to the id in Table
After the customer adds the product to the shopping cart, how can he get the total price of the product? for example, if the unit price of Apple is 10 yuan, the banana is 5 yuan, the dragon fruit is 8 yuan, and three apples are bought, two bananas and five pitaya. Currently, the database is designed as table a with id, item name, price, and Table B with id (corresponding to table a's id ), how can I get the final price for the number of purchased items (the simplest and most efficient way)? my current method is to first query all the data purchased by this customer in multiple tables, then, use the foreach loop array in php, multiply the price and the number, and add the result to the result. The efficiency is poor.
------ Solution --------------------
The reply was deleted by the administrator at 12:19:36.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.