如何在 LIKE 条件下使用代码点火器中的活动记录


How use active records in Codeigniter for LIKE condition?

在Codeigniter中如何使用OR?例如,我需要:

WHERE type LIKE 'test' OR type LIKE 'test2'

我想应该是这些:

$this->db->like();
$this->db->or_like();

https://ellislab.com/codeigniter/user-guide/database/active_record.html

(使用此搜索找到)。

你需要同时使用喜欢和or_like两者

$this->db->like('type', 'test', 'none');
$this->db->or_like('type', 'test2', 'none');

将产生

WHERE type LIKE 'test' or type LIKE 'test2'

请参阅文档以了解无、之前、之后

更新
在您的示例中,您仅与 2 键匹配,因此上述解决方案是可以的。
但是如果你想匹配像test1 test2 test3 test4 test5这样的五个键,你可以按照以下方式去做

    $array=array('test1','test2', 'test3','test4','test5');
    foreach($array as $item)
    {
        $this->db->or_like('type', $item, 'none');
    }