Jump to content

Search by features: NEED HELP


Recommended Posts


I-m writting a module wich search in product's features, but as I have no idea about SQL, I'm having problems. This is the code I'm using now:

       foreach ($features AS $feature) {
           $attr = $attr . '
               SELECT DISTINCT
               `'._DB_PREFIX_.'product` AS p,
               `'._DB_PREFIX_.'feature_product` AS fp,
               `'._DB_PREFIX_.'product_lang` AS pl,
               `'._DB_PREFIX_.'image` AS i,
               `'._DB_PREFIX_.'image_lang` AS il
               fp.`id_feature_value` = '. $feature .' AND 
               p.`id_product` = fp.`id_product` AND
               p.`id_product` = pl.`id_product` AND
               pl.`id_lang` = '.intval($id_lang).' AND        
               i.`id_product` = p.`id_product` AND
               i.`cover` = 1 AND
               p.`active` = 1
               GROUP BY

           if ($i != 1) {
               $attr = $attr . ' UNION ALL ';

This code is working now, but the problem is that is TOO slow because it makes a very long query (I have 9 features, so the there are 9 UNION ALL)

Any one could help me writing a better code???

Maybe the solution could be creating an extra table on the data base with the features in a better way....

thanks, and sorry about my english.

Share this post

Link to post
Share on other sites

I have discovered that the problem is with the images, if I erase the part with the tables 'image' and 'image_lang' the query is very fast, is any way to do it in two parts or something like that???

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More