[eluser]oddman[/eluser]
The reason for this dnyce, is because you have not created any relationship in the code between items and categories.
In order to do this, you need to update your get_catgames() function, as the logic is incorrect (its returning after one call, even though you're looping.
Try this:
Code:
function get_catgames($cat_data) {
$cat_items = array();
foreach ($cat_data['categories'] as $category) {
$items = array();
$query = 'SELECT id, items.desc, name, nameid, rating, cat FROM items WHERE cat = \''.$category['name'].'\' ORDER BY RAND() LIMIT 0, 5';
$result = $this->db->query($query);
foreach ($query->result_array() as $row)
{
$items[] = $row;
}
$cat_items[$row['cat']] = $items;
}
}
What we've done here is created a relationship between the categories and items, and stored each result in it's own array.
Code:
<?php foreach($categories as $category):?>
<li><?php echo "<br />".$category['name'];?></li>
<ul>
<?php foreach($items[$category['name']] as $item):?>
<li><?php echo $item['name']; ?></li>
<?php endforeach;?>
</ul>
<?php endforeach;?>
This is the code you want in your view. As you can see, we're referring to each $items array that contains the $category['name'] value. Also, just a bit of friendly advice - you're better off using IDs to link your data between tables, rather than strings (the category name), reason being is IDs are far easier for keys, and they're much more efficient for searching.
Hope that helps!