我有各种过滤器的网站,包括类别过滤器。用户可以选择多个类别,以及一个。在MYSQL数据库中,字段为'po_category'是一个数组(64,93,97)。所以,在codeigniter我有以下代码:
$kategorija = $this->input->post('kategorija');
$this->db->select('*');
$this->db->from('jobs');
if(!empty($kategorija)) {
$cat_array = explode(',', $kategorija);
$count_items = count($cat_array);
if($count_items == '1') {
$this->db->where("find_in_set($kategorija, po_category)");
} else {
$this->db->group_start();
$count = 0;
foreach($cat_array as $item) {
$count++;
if($count == '1') {
$this->db->where_in("find_in_set($item, po_category)");
} else {
$this->db->or_where("find_in_set($item, po_category)");
}
}
$this->db->group_end();
}
}
只有当我在过滤器中选择类别数组中的第一个数字(64)时,它才能正常工作。我想我必须使用'where_in',但它没有正常工作。
有什么建议吗?
2条答案
按热度按时间z6psavjg1#
CodeIgniter的
where_in
语法如下所示:为什么使用find_in_set?
ttcibm8c2#
您可以取代下列程式码:
使用
where_in
时: