gpt4 book ai didi

php - CodeIgniter Active Record 多个 WHERE 子句

转载 作者:行者123 更新时间:2023-11-29 02:55:29 25 4
gpt4 key购买 nike

我正在尝试转换此查询:

 SELECT * FROM table WHERE condition1 = 'example' AND (date1 = 'date' OR renewal1 = 'renewal');

转换为 CodeIgniter 的 Active Record 格式。我尝试了以下方法:

$q = $this->db->select('*');
$q = $this->db->from('table');
$q = $this->db->where('condition1 = condition');
$q = $this->db->where('date1 = date OR renewal = renewal');
$q = $this->db->get();
$results = $q->result();

但这并没有达到预期的效果。它似乎没有在第二组条件周围放置括号,这导致查询无法按预期工作。我还能怎么做才能代表我想要的东西?

感谢您的帮助!

最佳答案

你可以使用

$this->db->select('*');
$this->db->from('table');
$this->db->where('condition1 =',' condition');
$where = '(date1 = "date" OR renewal1 = "renewal")';// you can use your condition like this
$this->db->where($where);
$q = $this->db->get();
$results = $q->result();

关于php - CodeIgniter Active Record 多个 WHERE 子句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31141010/

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