我在codeigniter中有这样的代码
foreach ($where as $k=>$v){
foreach ($v as $val){
$this->db->or_where($k, $val);
}
}
but,我想要'or where group' like
select * from table where id = '1' and (category = 'tekno' OR category ='biologi');
任何想法?
如果需要对where子句进行更复杂的分组,我通常会手动构建查询。
$or_where = "";
foreach ($where as $k => $v) {
foreach ($v as $val) {
$or_where .= "OR category = '$val' ";
}
}
您可以添加到您现有的活动记录查询:
$this->db->where($or_where);
或
$this->db->or_where($or_where);
您可以在下面添加更多内容:
$this->db->where('id', 1);
$this->db->where('(category', 'tekno');
$this->db->or_where('category', 'biologi');
$this->db->where('1=1)');