Amazon has "Customers Who Bought This Item Also Bought".
I am wondering and want to add this to my shopping cart which I made.
What fields do I need in a database? Any website, blog or resources for this?
Can you suggest the mechanism how to I should code it please?
It's not too tricky. Assume you have the following tables:
To find the products you seek, you need to find the set of customers who have bought that particular product ID:
SELECT CustomerID
FROM (Customers INNER JOIN (Orders INNER JOIN OrderItems))
WHERE OrderItem.ProductID = <your product id here>
Then, you need to get the other products those customers have bought:
SELECT ProductID
FROM (Customers INNER JOIN (Orders INNER JOIN OrderItems))
WHERE (Customer = <given customer ID>) AND (ProductID <> <your product id>)
Then select the top few products and you're off to the races.
Note: I'm a numerical guy. The DB gurus will be able to do this in 1 query! :)
You need history of orders so that you can check for other items that were bought together with the item user is currently viewing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With