产品彩色滤光片

时间:2015-10-29 11:12:57

标签: php mysql filter

我为彩色滤镜做了代码并编写了这个查询,这些工作正常

select distinct(p.products_id), p.products_image, pd.products_name,
 pd.products_description, p.manufacturers_id, p.products_price, 
p.products_date_available, 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 products_description pd, products p left join 
manufacturers m on p.manufacturers_id = m.manufacturers_id left join 
specials s on p.products_id = s.products_id, products_to_categories p2c, 
colors_info ci, products_to_colors ptoc where p.products_status = '1' and 
p.products_id = p2c.products_id and pd.products_id = p2c.products_id and 
pd.language_id = '1' and p2c.categories_id = '22' and p.products_id = 
ptoc.products_id and ci.colors_id = ptoc.colors_id and ( ci.colors_id = 
'8' or ci.colors_id = '1' or ci.colors_id = '2' ) and ci.languages_id = 
'1' group by p.products_id order by pd.products_name

但我的客户写信给我,他需要用户选择红色(有4个产品)显示4个产品,如果用户也选择蓝色(有2个产品)

1 个答案:

答案 0 :(得分:0)

您可以在查询中使用mysql IN子句。

例如:

$colorIds = [1,2];  
$sql = "SELECT * FROM products WHERE color_id IN ($colorIds)";