[eluser]derekmichaeljohnson[/eluser]
I have a users, cats (id, name) and users_cats table (user_id, cat_id) which I join together like so:
Code:
$this->db->select('users.*, users_cats.cat_id, cats.name AS cat');
$this->db->from('users');
$this->db->join('users_cats', 'users.id = users_cats.user_id','left');
$this->db->join('cats', 'users_cats.cat_id = cats.id','left');
$users = $this->db->get();
Code:
<?php foreach($users->result() as $user) : ?>
<h3><?=$user->name?></h3>
<p>Category(s): <?=$user->cat?></p>
<?php endforeach; ?>
Looks like this:
Quote:John Smith
Category(s): Plumbing
Tom Brown
Category(s): Roofing
But if a user has multiple categories assigned to him in the "users_cats" table, like:
Code:
user_id cat_id
1 4
1 7
How can I get it to show both of them, or 3 or 4 or however many there are?
Thanks!