我编写了颜色过滤器代码并编写了这个查询,运行良好
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 个产品)
最佳答案
可以使用mysql IN您查询中的子句。
例如:
$colorIds = [1,2];
$sql = "SELECT * FROM products WHERE color_id IN ($colorIds)";
关于php - 产品用滤色片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33412663/