[eluser]jacobkball[/eluser]
Hi there,
A CI newbie question follows
I have a page where I want to list a series of db query results, but I'm having trouble getting my head around how to actually achieve it using models, controllers and views.
What I'm trying to get is:
Category One
- Cat One SubCat One (count of items in subcat)
- Cat One SubCat Two (count of items in subcat)
- Cat One SubCat Three (count of items in subcat)
Category Two
- Cat Two SubCat One (count of items in subcat)
- Cat Two SubCat Two (count of items in subcat)
- Cat Two SubCat Three (count of items in subcat)
and I have these three functions in my model:
Code:
function get_maincat_info () {
$query = $this->db->get('maincategories');
return $query->result();
}
function get_subcat_info ($maincatid) {
$query = $this->db->where('MainCatID',$maincatid);
$query = $this->db->get('subcategories');
return $query->result();
}
function get_item_count ($subcatid) {
$query = $this->db->where('SubCatID',$subcatid);
$query = $this->db->where('ShowItem','y');
$count = $this->db->count_all_results('iteminfo');
return $count;
}
Obviously, a loop is needed in my view:
Code:
<?php foreach ($results as $row) { ?>
<?php echo $row->MainCatName;?><br>
<?php foreach ($subcatresults as $subcatrow) { ?>
<a href="/search/<?php echo $row->MainCatLink . '/' . $subcatrow->SubCatLink; ?>/" class="catlink"><?php echo $subcatrow->SubCatName; ?></a> [ <?php echo $countresults[0]; ?> ]<br>
<?php
}
}
?>
but I don't know how to do it so that it loops through each main category, retrieves the sub category info AND count, and returns it to the view.
I don't think I've explained it very well, so let me know what other info you need to see what I'm actually trying to do!!
Hope someone can help
Cheers
Jacob