I like to convert following MySQL queries into Codeigniter Active Record Queries.
Following is 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
Codeigniter :
$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;
Kindly help me to get the above codes converted for Codeigniter Active Record.