[eluser]Dark Preacher[/eluser]
Maybe this kind of code will help..
Create function in one of your models, "get_ucats" for example
Code:
function get_ucats()
{
$data = array();
$q = $this->db->get('users');
if($q->num_rows() > 0)
{
foreach ($q->result_array() as $user)
{
$data[$user['id']]['user'] = $user['name'];
$qc = $this->db->where('user_id', $user['id'])->get('categorys');
if($qc->num_rows() > 0)
{
foreach ($qc->result_array() as $cat)
{
$data[$user['id']]['cats'][$cat['id']] = $cat['name'];
}
}
}
}
return $data;
}
and then in your view use it like this
Code:
$ucats = $this->m_common->get_ucats();
foreach($ucats as $user_id => $user)
{
if(isset($user['user']))
{
echo '<h1>'.anchor('user/'.$user_id, $user['user']).'</h1>';
if(isset($user['cats']) && is_array($user['cats']))
{
echo 'Category(s): ';
$count = count($user['cats']);
$i = 2;
foreach($user['cats'] as $cat_id => $cat)
{
echo anchor('category/'.$cat_id, $cat);
echo ($i++ <= $count)?', ':'';
}
}
}
echo '<br />';
}