具有嵌套“SELECT WHERE”的Codeigniter活动记录

时间:2014-04-03 22:01:37

标签: php mysql codeigniter activerecord

我想知道Active Record中是否有任何方法可以创建一个嵌套WHERE案例的查询,如:

SELECT * FROM Users WHERE FirstName = 'John' AND (LastName = 'Smith' OR LastName = 'Jones');

2 个答案:

答案 0 :(得分:2)

是的,您可以使用where()功能

$this->db->select('*');
$this->db->from('Users ');
$this->db->where("FirstName = 'John'");
$this->db->where(" (LastName = 'Smith' OR LastName = 'Jones') ");
$result=$this->db->get();

Active Record

答案 1 :(得分:0)

您需要传递WHERE子句才能执行此操作。

$this->db->where("FirstName = 'John' AND (LastName = 'Smith' OR LastName = 'Jones')");