【问题标题】:CodeIgniter Active Record multiple WHERE clausesCodeIgniter Active Record 多个 WHERE 子句
【发布时间】:2015-09-17 09:52:39
【问题描述】:

我正在尝试转换此查询:

 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();

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

感谢您的帮助!

【问题讨论】:

    标签: php mysql codeigniter activerecord


    【解决方案1】:

    你可以使用

    $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();
    

    【讨论】:

    • 这会将最后两个条件与第一个条件分开,以便它们作为一个块一起运行吗?如果这是有道理的......
    • 检查更新的答案。它会分开你的条件
    猜你喜欢
    • 2013-09-26
    • 2017-11-30
    • 1970-01-01
    • 2015-07-31
    • 1970-01-01
    • 2015-08-10
    • 2016-02-25
    • 1970-01-01
    • 2013-02-27
    相关资源
    最近更新 更多