Click here to Skip to main content
15,890,382 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi to all, i ' m developing a E-Commerce web site, but i have problem with this : how can i bring parameters between tables of my db ?
Let me explain better, i have a page where you click buy an item, and then add it to Shopping cart (another db table) , but unitl now i pass only the id through navigation url and take it in page load with request.querystring.
How can i complete the table Shopping Cart with Name of the Item, Price and Quantity ?

Thank you so much.

What I have tried:

[removed]
Posted
Updated 29-Mar-17 22:38pm
v2
Comments
EmanuelPirovano 30-Mar-17 11:44am    
Thank you man.

I' ve find another way : INSERT INTO TABLEX(ID,NAME...) SELECT ID,NAME... FROM TABLEY

1 solution

Normally you would only store the ID and whenever you wanted to show the basked you would JOIN your Basket table on your Product table on the ID, effectively creating a virtual table that has all the fields from both tables, so you can now access the product name etc

SELECT * FROM Basket B JOIN Product P on B.ProductID = P.ID


However for a basket you might want to copy things like the price across into your Basket table. So when it is added to the basket store the product ID but also store the price. The reason for doing this is in case the price changes. If it was "£10" when I added it to my basket and the price changes it should still be listed as "£10" in my basket as you are making a contract with the customer when they add something to their basket that they are buying that item at that price.

So to show your basket you would still do the join, but the product name, description etc would come from the product table (P.Name, P.Description in the above query) but you would get the price from the basket table (B.Price).
 
Share this answer
 
Comments
Richard Deeming 30-Mar-17 12:01pm    
"... you are making a contract with the customer when they add something to their basket that they are buying that item at that price."

IANAL, but I don't think that's right. If a customer puts something in their basket today, and then comes back next week to check out, I don't think it's unreasonable to expect them to pay the current price. The "contract" happens at the point when they check out.
F-ES Sitecore 30-Mar-17 12:17pm    
I didn't say legal contract. In the world of ecommerce it is generally taken that when you add an item to a basket you are promising the customer that item at that price (if possible) and to act otherwise would be unethical. Not illegal, but unethical.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900