【问题标题】:AND OR in where with codingniterAND OR 在哪里使用 codeigniter
【发布时间】:2014-08-23 07:22:11
【问题描述】:

我在 codeigniter 中使用 WHERE 函数时遇到问题。 假设我们有两个数组如下:

    $t1=arrray('a','b');
    $t2=array('c','d');

我想对数组$t1 中的元素做OR,我也想对数组$t2 中的元素做OR。然后我想做两个数组的 AND 结果。

例如

where (table1.id='a' or table1.id='b') and (table2.id='c' or table2.id='d').

如何在 codeigniter 中设置?

【问题讨论】:

  • $this->db->where("(table1.id='a' or table1.id='b') and (table2.id='c' or table2.id='d')");

标签: php sql codeigniter


【解决方案1】:
$this->db->where("(table1.id='a' OR table1.id='b')");
$this->db->where("(table2.id='c' OR table2.id='d')");

【讨论】:

    【解决方案2】:
    $where = "(table1.id='a' OR  table1.id='b') AND (table2.id='c' or table2.id='d')";
        $this->db->where($where);
    

    【讨论】:

    • 您能解释一下答案中的代码吗?没有任何解释的两行代码不被认为是 SO 中的正确答案(来自审查)。
    • 请编辑您的答案以添加对您的代码如何工作以及它如何解决 OP 问题的解释。许多 StackOverflow 用户是新手,不会理解您发布的代码,因此不会从您的回答中学习。
    猜你喜欢
    • 2018-11-23
    • 1970-01-01
    • 2012-10-10
    • 2015-03-08
    • 2012-11-06
    • 1970-01-01
    • 1970-01-01
    • 2010-12-12
    • 1970-01-01
    相关资源
    最近更新 更多