Hi David, I would like to offer my visitors a random choice from the database of about nine products. However, is it possible to tailor the results depending on the page they are visiting? i.e. my health and beauty page.
Regards
Rob
Hi David, I have had a good go at this but confused about just what to change in html/randomproducts.php to display the items as required.
Sorry to be a pain but up to now I have never used php. Managed to get random products for featured to display but now stuck.
Changed 2 lines in the random.php (copy of featured.php)to:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` ORDER BY RAND() LIMIT 9";
if (isset($featured)) require("html/randomproducts.php");
Regards Rob
Hi Rob,
My apologies - I missed your reply to this thread.
Which page(s) do you want to display the random products on? The home page presumably has no category specific information available - so I'm wondering if it is search.php that you want to incorporate this into....?
Once i've established exactly where you want the products to appear, i'll ask you to email me your modified files and I'll try and merge the changes in for you...
Cheers,
David.
Hi David, I thought I was going to crack this to save you the trouble. Bet it's really easy :-). Once I have the main sql I can alter for each page that I want random products on. My landing page actually includes the featured.php. So, I would expect to just copy the landing page and then replace the select statement for the featured.php to get the random products FROM the products table rather than the featured table. But as soon as I alter the select from, I get no results. What am I doing wrong???
Regards Rob
Hi Rob,
It should just be a case of changing the SQL, so i'm not sure why you're getting no results. If you email me one of the modified files (where you have changed the SQL) i'll take a look for you - reply to your reg code for forum registration email is the easiest way to get me...!
Cheers,
David.
Hi Rob,
Should be straight forward - have you already implemented random products without the tailoring? The main details are in this thread - essentially you just take the feature products code from index.php and change the SQL statement to select random products rather than reading the featured products table...
http://www.pricetapestry.com/node/578
To modify this for the particular page; you would need to add a WHERE clause to the SQL; and i'm assuming that this would be based on category. So, for your Health and Beauty page, the code would be (for 9 products):
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE category='Health and Beauty' ORDER BY RAND() LIMIT 9";
Or to pick from more than one category:
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE category IN ('Category 1','Category 2','Category 3') ORDER BY RAND() LIMIT 9";
Cheers,
David.