Jump to content

LEFT JOIN


RainbowSix

Recommended Posts

Salve ho un piccolo problema
devo estrapolare dei dati aggiuntivi
dalla seguente query
insomma per farla breve devo estrapolare anche i dati contenuti
in ps_image e ps_image_lang

   static public function getProducts($id_lang, $start, $limit, $orderBy, $orderWay, $id_category = false, $only_active = false)
   {
       if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay))
           die (Tools::displayError());
       if ($orderBy == 'id_product' OR    $orderBy == 'price' OR    $orderBy == 'date_add')
           $orderByPrefix = 'p';
       elseif ($orderBy == 'name')
           $orderByPrefix = 'pl';
       elseif ($orderBy == 'position')
           $orderByPrefix = 'c';

       $rq = Db::getInstance()->ExecuteS('
       SELECT p.*, pl.* , t.`rate` AS tax_rate, m.`name` AS manufacturer_name, s.`name` AS supplier_name, i.`id_image`, il.`legend`, il.`link_img`
       FROM `'._DB_PREFIX_.'product` p
       LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`)
       LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = p.`id_tax`)
       LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)
       LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'.
       ($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').'
       WHERE pl.`id_lang` = '.intval($id_lang).
       ($id_category ? ' AND c.`id_category` = '.intval($id_category) : '').
       ($only_active ? ' AND p.`active` = 1' : '').'
       ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay).
       ($limit > 0 ? ' LIMIT '.intval($start).','.intval($limit) : '')
       );
       if($orderBy == 'price')
           Tools::orderbyPrice($rq,$orderWay);

       return ($rq);
   }



ora se aggiungo

       LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)
       LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image`)



non mi restituisce nulla delle due tabbelle in oggetto ... come devo fare? dov'è che sbaglio?
Help me ... please!

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...