将查询转换为codeigniter

时间:2015-04-14 13:59:31

标签: php codeigniter

我在codeigniter工作。我想知道,如何在codeigniter中编写下面的代码..

SELECT p.* FROM people p WHERE p.age = (select max(subp.age) from people subp);

2 个答案:

答案 0 :(得分:1)

这将有效

$this->db->select('p.*');
$this->db->from('people p');
$this->db->where('p.age = (select max(subp.age) from people subp)',null,false);
$result = $this->db->get()->result_array();
print_r($result);

答案 1 :(得分:0)

有很多方法可以做到这一点,例如

$sql = 'SELECT p.* FROM people p WHERE p.age = (select max(subp.age) from people subp)';
$query = $this->db->query($sql);
$result = $query->result_array();