Jump to content

Search by features: NEED HELP


superisc

Recommended Posts

Hi,

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
               p.*,
               pl.`description_short`,
               pl.`link_rewrite`,
               pl.`name`,
               i.`id_image`,
               il.`legend`,
               fp.`id_feature_value`
               FROM
               `'._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
               WHERE
               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
               p.`id_product`';
           }

           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.

Link to comment
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...