【问题标题】:Datatables - where with two conditions数据表 - 有两个条件
【发布时间】:2020-07-02 20:34:50
【问题描述】:

我使用以下语句按主题 ID 过滤记录。 (这里subject_id=5)

$this->datatables->where('letter_letter.subject_id', 5);

这是完美的工作。此外,我想过滤 subject_id 范围内的记录,例如 1 到 10。然后我将代码更改如下:

$this->datatables->where('letter_letter.subject', 10, '<');

但是没有得到想要的输出。如何编辑我的代码以获得预期的结果?谁能帮帮我?

【问题讨论】:

    标签: mysql datatable codeigniter-3


    【解决方案1】:

    只需对where() 进行两次调用即可定义范围:

    $this->datatables->where('letter_letter.subject_id >= ', 1);
    $this->datatables->where('letter_letter.subject_id <=', 10);
    

    【讨论】:

      【解决方案2】:

      这是您可以使用两个条件进行where 查询的一种方式:

      $this->datatables->where("letter_letter.subject_id IS ? AND letter_letter.subject BETWEEN ? AND ?", 5, 1, 10)
      

      【讨论】:

        猜你喜欢
        • 2015-12-09
        • 2018-01-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-10-09
        • 1970-01-01
        相关资源
        最近更新 更多