I'd like to implement a function where we show the customer products in the shipping cart, which were also bought by others. at least the most popular products.
in example if the customer has product no. 5 in the shopping cart, the select should check what kind of products were also bought with product no. 5, count them and output the most popular ones...
our table looks like this:
CREATE TABLE orders_products (
orders_products_id int(11) NOT NULL auto_increment,
orders_id int(11) DEFAULT '0' NOT NULL,
products_id int(11) DEFAULT '0' NOT NULL)
(i have purged fields we don't need here).
Any idea how I could do that select? I thought about selecting the orders_id's first, then go through each order, count the products etc... and when i am through all orders and products, I should have the result in an array. I could then use this array to output the 5 popular ones.
but this would be very heavy for the CPU and for mysql (about 100 000 rows in the table, where it is about 3000 different order_id's).
Alex