数据表 - 有两个条件

Datatables - where with two conditions

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

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

效果很好。此外,我想过滤 subject_id 范围内的记录,例如 1 到 10。然后我将代码更改如下:

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

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

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

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

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

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