Tricky GROUP BY
Hej eksperterJeg er ved at tilrette noget gammel kode.
Jeg skal lave en group by på p.products_id, som der allerede bliver gjort. Derfor skal der laves en group by p.collection_id, men dem hvor collection_id er lig med 0 (tallet) skal ikke grupperes. Det er altså kun dem med 1,2,3,4,5 osv der skal grupperes.
Koden er nu:
$listing_sql = "select " . $select_column_list . " p.products_id, p.manufacturers_id, p.products_price, p.products_tax_class_id, IF(s.status, s.specials_new_products_price, NULL) as specials_new_products_price, IF(s.status, s.specials_new_products_price, p.products_price) as final_price from " . TABLE_PRODUCTS_DESCRIPTION . " pd
left join " . TABLE_PRODUCTS . " p on p.products_id = pd.products_id
left join " . TABLE_MANUFACTURERS . " m on p.manufacturers_id = m.manufacturers_id
left join " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c on p.products_id = p2c.products_id
left join " . TABLE_SPECIALS . " s on p.products_id = s.products_id
where p.products_status = '1' and pd.language_id = '" . (int)$languages_id . "' and p2c.categories_id = '" . (int)$current_category_id . "' and ".(int)$current_category_id." IN ( SELECT categories_id FROM categories WHERE ((customers_groups_id = '') or (customers_groups_id is NULL) ) ) and ( (p.givskovcykler = 0) ".
//petyus filter
(($_SESSION['is_own_site']) ? " or (p.givskovcykler = 1) " : "" ) .
(($_SESSION['cykeldillen']) ? " or (p.givskovcykler = 10) " : "" ) . ") ".
" GROUP BY p.products_id ";