gpt4 book ai didi

php - 或者 codeigniter 上的 where group

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:30 25 4
gpt4 key购买 nike

我在 codeigniter 中有这样的代码

foreach ($where as $k=>$v){
foreach ($v as $val){
$this->db->or_where($k, $val);
}
}

但是,我想要'或where group'之类的

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' ";
}
}

然后您可以添加到现有的 Active Record 查询:

$this->db->where($or_where);

$this->db->or_where($or_where);

关于php - 或者 codeigniter 上的 where group,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15288882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com