[eluser]morcegon[/eluser]
[quote author="Developer13" date="1189923191"]Will your subcategories also contain subcategories?
If so, you'll need to look into recursive functions. If you're newish to PHP or any other language, it might be a bit frustrating to wrap your head around.
But it sounds like you're on the right track with what you're doing. I am having trouble understanding exactly what you need help with - it looks like you have the logic of what needs to happen down.
Your model should contain two functions:
mdl_categories:
Code:
function getCategories() {
$this->db->where("parentid = 0 AND active = 1");
$this->db->orderby("category");
$query = $this->db->get("categories");
return ($query->result());
}
function getSubCategories($parentid) {
$this->db->where("parentid = {$parentid} AND active = 1");
$this->db->orderby("category");
$query = $this->db->get("categories");
return ($query->result_array());
}
Then in your controller:
Code:
function whatever() {
$dbCategories = $this->mdl_categories->getCategories();
foreach ($dbCategories as $dbCategory) {
$categories[$dbCategory->category]['name'] = $dbCategory->category;
$categories[$dbCategory->category]['subcategories'] = $this->mdl_categories->getSubCategories($dbCategory->id);
}
}
This particular example doesn't include recursion, but it will put all your categories and subcategories into an array that you can then process in your view.[/quote]
Its a very best solution for my throuble, thanks dude.!!!