Php 或者在codeigniter上的哪个组
我在codeigniter中有这样的代码Php 或者在codeigniter上的哪个组,php,mysql,codeigniter,Php,Mysql,Codeigniter,我在codeigniter中有这样的代码 foreach ($where as $k=>$v){ foreach ($v as $val){ $this->db->or_where($k, $val); } } 但是,我想要的是“或者说是哪一组”之类的 select * from table where id = '1' and (category = 'tekno' OR category ='bio
foreach ($where as $k=>$v){
foreach ($v as $val){
$this->db->or_where($k, $val);
}
}
但是,我想要的是“或者说是哪一组”之类的
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);
或
如果需要更复杂的where子句分组,我经常求助于手动构建查询
$or_where = "";
foreach ($where as $k => $v) {
foreach ($v as $val) {
$or_where .= "OR category = '$val' ";
}
}
然后,您可以将以下内容添加到现有活动记录查询中:
$this->db->where($or_where);
或
您可以在以下位置添加更多内容:
$this->db->where('id', 1);
$this->db->where('(category', 'tekno');
$this->db->or_where('category', 'biologi');
$this->db->where('1=1)');
您可以在以下位置添加更多内容:
$this->db->where('id', 1);
$this->db->where('(category', 'tekno');
$this->db->or_where('category', 'biologi');
$this->db->where('1=1)');
你的代码到底给了你什么,相对于你想要它给你什么?你的代码到底给了你什么,相对于你想要它给你什么?