【发布时间】:2018-05-30 06:39:11
【问题描述】:
这就是我在查询中使用 FIND_IN_SET 的方式,它在查询中自动添加 IS NULL 并且还需要在 WHERE s.cat_id = '11' AND 查询之后添加括号
$spilt=explode(',',$newstyle);
foreach ($spilt as $splitkey => $splitvalue) {
if ($splitkey == 0) {
$this->db->where("FIND_IN_SET(".$splitvalue.",w_card_style)");
}
else{
$this->db->or_where("FIND_IN_SET(".$splitvalue.",w_card_style)");
}
}
当我使用$this->db->last_query() 打印查询时,它会给出类似的查询
SELECT `c`.`city_name`, `s`.`name`, `s`.`location`, `s`.`starting_price`, `s`.`budget_range`, `s`.`cat_id`, `s`.`id`, `i`.`path`, `s`.`specification_status`, `s`.`per_unit_charge`, `s`.`w_card_style`, `s`.`w_card_style`, `s`.`budget_range` FROM `image_gallery` as `i` JOIN `specification` as `s` ON `i`.`ser_id`=`s`.`id` JOIN `cities` as `c` ON `c`.`city_id`=`s`.`location` JOIN `wcard_style` as `ws` ON `ws`.`id`=`s`.`w_card_style` WHERE `s`.`cat_id` = '11' AND FIND_IN_SET(1,w_card_style) IS NULL OR FIND_IN_SET(2,w_card_style) IS NULL OR FIND_IN_SET(3,w_card_style) IS NULL AND budget_range BETWEEN 50 AND 100 GROUP BY `ser_id` HAVING `cat_id` = '11' ORDER BY `s`.`budget_range` DESC
在每个 FIND_IN_SET 之后都有 IS NULL,那么如何从 Query 中删除 IS NULL 并且还需要在运行时像这样在“ WHERE s.cat_id = '11' AND ”之后添加括号
SELECT `c`.`city_name`, `s`.`name`, `s`.`location`, `s`.`starting_price`, `s`.`budget_range`, `s`.`cat_id`, `s`.`id`, `i`.`path`, `s`.`specification_status`, `s`.`per_unit_charge`, `s`.`w_card_style`, `s`.`w_card_style`, `s`.`budget_range` FROM `image_gallery` as `i` JOIN `specification` as `s` ON `i`.`ser_id`=`s`.`id` JOIN `cities` as `c` ON `c`.`city_id`=`s`.`location` JOIN `wcard_style` as `ws` ON `ws`.`id`=`s`.`w_card_style` WHERE `s`.`cat_id` = '11' AND (FIND_IN_SET(1,w_card_style) IS NULL OR FIND_IN_SET(2,w_card_style) IS NULL OR FIND_IN_SET(3,w_card_style) IS NULL ) AND budget_range BETWEEN 50 AND 100 GROUP BY `ser_id` HAVING `cat_id` = '11' ORDER BY `s`.`budget_range` DESC`enter code here`
【问题讨论】:
标签: php mysql sql codeigniter filter