how to show 6 randomly selected featured products?
| From: | afan at afan dot net | Date: | Mon, 06 Feb 2006 04:56:46 +0000 |
| Subject: | how to show 6 randomly selected featured products? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229910@lists.php.net to get a copy of this message | ||
Hi,
I have to show 6 of up to 1000 (most likely 200-600) featured products on
my online store.
My first thought was using this query:
$query = mysql_query("
SELECT p.prod_id, p.prod_name, p.prod_no, pr.price_id, pr.method,
pr.qty, pr.price, pr.sale_price, chp.cat_id
FROM products as p
LEFT JOIN prices as pr ON pr.prod_id = p.prod_id
LEFT JOIN categories_has_products as chp ON chp.prod_id = p.prod_id
ORDER BY RAND() LIMIT 6
");
but I needed 4 to 6 secunds to finish downloading the page.
Then I tried as a solution to grab all featured products from db, store
them as an array in $_SESSION[FEFATURED_PRODUCTS] and then evey time
actually just grab randomly 6 products form the array.
The home page is now much faster, of course, but I'm not sure how "smart"
is keep an array with 1000 elements in $_SESSION?
Thanks for any opinion!
:)
-afan