Welcome Guest, Not a member yet? Register   Sign In
Join Question
#3

[eluser]derekmichaeljohnson[/eluser]
Works great!

Only problem is it doesn't show categories that don't have any users assigned to it yet. How can I get it to display empty categories with a zero?

EDIT:

Answered my own question... just made it a LEFT join. I also took the "users" table out of the query, as I don't really need user information for this particular usage. Here's my final code:

Code:
$this->db->select('cats.*, users_cats.cat_id, COUNT(users_cats.user_id) as user_count');
$this->db->from('cats');
$this->db->join('users_cats', 'users_cats.cat_id = cats.id','left');
$this->db->group_by("cats.id");
$data['cats'] = $this->db->get();


Messages In This Thread
Join Question - by El Forum - 07-05-2009, 05:19 PM
Join Question - by El Forum - 07-05-2009, 06:21 PM
Join Question - by El Forum - 07-05-2009, 06:31 PM
Join Question - by El Forum - 07-05-2009, 08:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB