Page 1 of 1

WHERE items ARE in Category_1 OR THEN in Category_2??

Posted: Wed Sep 08, 2010 12:35 pm
by simonmlewis
Hi.
We have a load of products and want to show best sellers from the category a product is it.

ie. if you sell cars, and you are hundreds of Fords. You want to show a particular Ford page, but then show all your best selling fords.

What if you run out of Fords? You want to then also maybe show Jaguar's or ANY OTHER cars in your Lot.. So your query is a randomly selected query for about 16 items, firstly looking for those Fords in the system, but if you only have 4 Fords, it then finds ANY (*) other products randomly.

Code: Select all

$result = mysql_query ("SELECT * FROM products WHERE best = 'yes'  AND pause = 'off' AND photoprimary IS NOT NULL ORDER BY RAND() LIMIT 0, 12");
Is there something I can add to this script that will do that?

Re: WHERE items ARE in Category_1 OR THEN in Category_2??

Posted: Wed Sep 08, 2010 2:33 pm
by califdon
I don't think I would do that. If they are sorted randomly, the primary items might not make the Limit cut, which I would think would defeat the whole purpose. I would probably use a UNION query, the first part of which recovers the items you know you want, then the second part could be a random selection of others, excluding the criteria used in the the first part. In case you are not familiar with UNION queries, a search on Google will yield tons of references.