У меня есть совпадения в основной таблице.
Код: Выделить всё
id match_name
1 match 1
2 match 2
3 match 3
4 match 4
Код: Выделить всё
id user_id match_id registration_success
1 56 1 true
2 29 1 true
3 24 1 true
Мой код SQL:
Код: Выделить всё
$this->db->select('m.id, count(e.id) AS total_entries');
$this->db->from('matches m');
$this->db->join('match_entries e', "m.id=e.match_id",'LEFT');
$this->db->group_by('e.match_id');
$this->db->order_by('m.id', 'ASC');
$query = $this->db->get();
$row = $query->result();
if (empty($row))
return FALSE;
return $row;
Код: Выделить всё
[{"id":"1","total_entries":"3"},{"id":"2","total_entries":"0"}]
Что не так с кодом? Любая помощь приветствуется!
Подробнее здесь: https://stackoverflow.com/questions/549 ... count-join
Полная версия