Код: Выделить всё
city_id name
1 c1
2 c2
Код: Выделить всё
id city_city_id status_status_id
1 1 1
2 2 1
3 1 2
Модель приведена ниже:
Код: Выделить всё
function count(){
$this->db->select('*');
$this->db->from('city');
$this->db->join('info','info.city_city_id= city.city_id');
$this->db->group_by('city_city_id');
$sql=$this->db->get();
if ($sql->num_rows()>0){
foreach ($sql->result() as $row){ //loops through all the cities in city table
$r=1;
$this->db->where('city_city_id','city.city_id');
$this->db->where('status_status_id', $r);
echo $this->db->count_all_results('info');
}
Заранее спасибо.
Подробнее здесь: https://stackoverflow.com/questions/837 ... d-group-by
Мобильная версия