php - 产品用滤色片

标签 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 个产品)

最佳答案

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

例如:

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

关于php - 产品用滤色片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33412663/

相关文章:

php - 显示数据库中的主题标签

mysql - c# 如何解决错误 mysql 使用的命令不允许 1148?

php - 将关键字转换为对应的拼音

javascript - jQuery 多面过滤器问题。

php - 在 PHP 中回显嵌套数组中的值

php - pg_fetch_assoc 返回 bool 值

sql - 限制非唯一值的返回

sql - 如何在sql中获取按ID分组的最大行数

javascript - Ruby on Rails - 同一数据有两个不同的过滤器

php - 如何将变量输入到准备好的 stmt 中以从列中检索所有内容?