Code: Select all
return $this->db
->select('forumCategories.id, forumCategories.name, forumCategories.order, forumCategories.date_created, COUNT(forumPosts.forumCategory_id) as postCount')
->from('forumCategories')
->join('forumPosts', 'forumCategories.id = forumPosts.forumCategory_id', 'left')
->group_by('forumPosts.forumCategory_id')
->order_by('forumCategories.order DESC')
->get()
->result_array();
Beispiel:
Code: Select all
Category 1 | 16 posts
Category 2 | 3 posts
Category 3 | 0 posts
Category 4 | 0 posts
Category 5 | 0 posts
Category 6 | 0 posts
Mobile version