Re: how to show 6 randomly selected featured products?
| From: | Chris | Date: | Mon, 06 Feb 2006 05:45:03 +0000 |
| Subject: | Re: how to show 6 randomly selected featured products? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-229912@lists.php.net to get a copy of this message | ||
Hi,
Sounds like your query isn't indexed properly.
Check you have an index on:
products.prod_id (primary key - should be indexed already)
prices.prod_id
categories_has_products.prod_id
afan@afan.net wrote:
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