Здравствуйте! При добавлении приведенного ниже фильтра почему-то выводятся товары из всех групп
/* Если ограничиваем по рейтингу */
if(isset($_GET['r5']) && $_GET['r5'] == 'on'){
$DataBase = & singleton('DataBase');
//Выбираем все id товаров и их средний рейтинг
$query = 'SELECT shop_comment_table.shop_items_catalog_item_id, Sum(shop_comment_table.shop_comment_grade)/Count(shop_comment_table.shop_comment_grade) as comment_grade FROM shop_comment_table GROUP BY shop_comment_table.shop_items_catalog_item_id';
$result = $DataBase->select($query);
if ($result)
{
while($row = mysql_fetch_assoc($result))
{
//Копируем все идентификаторы товаров со средним рейтингом = 5
if($row['comment_grade'] == 5)
$item_ids[] = $row['shop_items_catalog_item_id'];
}
}
//Ограничиваем по выбранным идентификаторам
$element['type'] = 0;
$element['prefix'] = 'and';
$element['name'] = 'shop_items_catalog_table.shop_items_catalog_item_id';
$element['if'] = '=';
$element['value'] = $item_ids[0];
$element['sufix'] = '';
$param['select'][] = $element;
if(sizeof($item_ids) > 1){
for($i=1; $i<sizeof($item_ids); $i++){
$element['type'] = 0;
$element['prefix'] = 'or';
$element['name'] = 'shop_items_catalog_table.shop_items_catalog_item_id';
$element['if'] = '=';
$element['value'] = $item_ids[$i];
$element['sufix'] = '';
$param['select'][] = $element;
}
}
$external_propertys['r5'] = 'on';
$external_propertys['apply_filter'] = true;
}
Запрос получается такой:
SELECT SQL_CALC_FOUND_ROWS DISTINCT shop_items_catalog_table.shop_items_catalog_item_id ,IF (shop_items_catalog_table.shop_currency_id = 3, shop_items_catalog_table.shop_items_catalog_price * 23.639664, IF (shop_items_catalog_table.shop_currency_id = 2, shop_items_catalog_table.shop_items_catalog_price * 36.889479, IF (shop_items_catalog_table.shop_currency_id = 1, shop_items_catalog_table.shop_items_catalog_price * 1, shop_items_catalog_price))) AS item_price_absolute FROM shop_items_catalog_table WHERE shop_items_catalog_table.shop_items_catalog_is_active = '1' AND shop_items_catalog_table.shop_items_catalog_modification_id = '0' AND shop_items_catalog_table.shop_items_catalog_access IN(0,-1) AND shop_items_catalog_table.shop_shops_id='1' AND shop_items_catalog_table.shop_groups_id = '601' AND (shop_items_catalog_table.shop_items_catalog_putend_date >= '2010-12-15 16:41:50' OR shop_items_catalog_table.shop_items_catalog_putend_date ='0000-00-00 00:00:00') AND shop_items_catalog_table.shop_items_catalog_putoff_date <= '2010-12-15 16:41:50' and shop_items_catalog_table.shop_items_catalog_item_id = '45' or shop_items_catalog_table.shop_items_catalog_item_id = '47' or shop_items_catalog_table.shop_items_catalog_item_id = '55' or shop_items_catalog_table.shop_items_catalog_item_id = '59' or shop_items_catalog_table.shop_items_catalog_item_id = '202' HAVING 1 ORDER BY shop_items_catalog_table.shop_items_catalog_order Asc, shop_items_catalog_table.shop_items_catalog_name Asc LIMIT 0, 3