I think(hope :)) I got it right: table products prod_id is primary key table prices price_id is primary key prod_id is foreign key table categories_has_products (since one product can be in more then one category, I have this table with only two columns: cat_id and prod_id, to link table between categories and products) cat_id, prod_id - product key > 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@xxxxxxxx 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 >> > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php