Hi,
Would the following be possible?
I would like my frontpage to show products automatically but based on some criteria.
For example it should allways show 12 products.
The twelve products are selected based on some search queries. Looking for some brands, categories or productnames and with some price range and selecting the lowest price for those queries.
Hi,
How what that be if I wanted to combine it?
For example show one Widget product and one Foo product?
And what if I want to sort it by ascending price?
And is it possible to have wildcard with an AND? For example Foo and Friend ?
Hi Marco,
The problem with selecting n random with different criteria is that they can't be done in the same query; so to achieve that would require multiple queries and then merging the results. It can be done, but as selecting by RAND() isn't the most efficient process in the first place I would advise against it if possible.
Logic ANDing the wildcard clauses is each, for example:
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE name LIKE '%Foo%' AND name LIKE '%Friend%' AND price >= 50.00 AND price <= 100.00 ORDER BY RAND() LIMIT 12";
Ordering by ascending price would need to be added to the second part of the featured products code where the full details are selected. In your index.php, search for:
ORDER BY sequence
...and REPLACE with:
ORDER BY price ASC
Cheers,
David.
--
PriceTapestry.com
Hi Marco,
Sure - you can add a WHERE clause to the basic Random Featured Products mod described in this thread. For example to select from the category Widgets with a price range of 50.00 to 100.00, use:
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE category='Widgets' AND price >= 50.00 AND price <= 100.00 ORDER BY RAND() LIMIT 12";
For product names matching a keyword, you can use LIKE and % as a wildcard, so this example will randomly select from products containing "Foo" and the same price range...
$sql = "SELECT name,1 AS sequence FROM `".$config_databaseTablePrefix."products` WHERE name LIKE '%Foo%' AND price >= 50.00 AND price <= 100.00 ORDER BY RAND() LIMIT 12";
Hope this helps!
Cheers,
David.
--
PriceTapestry.com