> When you select an item to look at, there is a section named: > > Customers who bought this item also bought: > > blah link one - blah description > blah link two - blah description > > How is this done? Is there a reference to a new db which has the links and > references them from there or do they look into sessions or cookies?
It seems pretty straight-forward; Each customizer has an account; when you go to buy something you have to sign in. When you buy something, a record is kept, 'this user' bought 'this item'. To get the referrals, we search for all users who bought the current item, then search for all items bought by those users (except the current item). Summary so far: Table: user userID, name, username, password, cc#, etc Table: items itemID, name, description, price, etc Table: purchases userID, itemID, date First search: SELECT DISTINCT userID FROM purchases WHERE itemID=$currentItemId; ... turn all returned userIDs into a comma-delimited list... Second search: SELECT itemID, COUNT(itemID) AS num FROM purchases WHERE userID IN ( $userList ) AND itemID != $currentItemId GROUP BY itemID ORDER BY num DESC LIMIT 5 ... returns the 5 most popular also-bought items. A database supporting sub-searches would make this very simple, but I think a good coder could turn this into a single query even in MySQL through clever use of joins. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php