Php Codeigniter活动记录中的多个Select Count SQL查询
我喜欢将以下MySQL查询转换为Codeigniter活动记录查询 以下是MySQL:Php Codeigniter活动记录中的多个Select Count SQL查询,php,mysql,codeigniter,Php,Mysql,Codeigniter,我喜欢将以下MySQL查询转换为Codeigniter活动记录查询 以下是MySQL: select brand_id,name,(select count(*) from items where brand_id = b.brand_id) as itemc, (select count(*) from models where brand_id = b.brand_id) as modelc from brands as b 编码点火器: $this->db->limit($p
select brand_id,name,(select count(*) from items where brand_id = b.brand_id) as itemc, (select count(*) from models where brand_id = b.brand_id) as modelc from brands as b
编码点火器:
$this->db->limit($perpage,$page);
$query = 'select brand_id,name,(select count(*) from items where brand_id = b.brand_id) as itemc, (select count(*) from models where brand_id = b.brand_id) as modelc from brands as b limit '.$perpage.' offset '.$page.'';
$query = $this->db->query($query);
$query = $query->result();
return $query;
请帮助我将上述代码转换为Codeigniter活动记录。以下是活动记录中的查询
$rows = $this->db->select('b.brand_id,b.name')
->select('(select count(*) from items where brand_id = b.brand_id) as itemc',FALSE)
->select('(select count(*) from models where brand_id = b.brand_id) as modelc',FALSE)
->from('brands as b')
->limit($perpage,$page)->get()->result();
这是活动记录中的查询
$rows = $this->db->select('b.brand_id,b.name')
->select('(select count(*) from items where brand_id = b.brand_id) as itemc',FALSE)
->select('(select count(*) from models where brand_id = b.brand_id) as modelc',FALSE)
->from('brands as b')
->limit($perpage,$page)->get()->result();