![]() |
Forum Categories - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Forum Categories (/showthread.php?tid=49611) |
Forum Categories - El Forum - 02-26-2012 [eluser]coxdabd[/eluser] Hi all, I'm coding up a custom forum for a client, looking very good. Hit a bit of a wall on how I should fetch the categories and subcategories. I'm ok getting the categories in a model, but then I also need to fetch the subcategories of that category - I was going to use a foreach loop in the view. Any ideas on how this can be achieved would be appreciated as I can't continue without a little help ![]() Forum Categories - El Forum - 02-27-2012 [eluser]coxdabd[/eluser] Anyone got any ideas? Forum Categories - El Forum - 02-27-2012 [eluser]meigwilym[/eluser] Show your code. Forum Categories - El Forum - 02-27-2012 [eluser]coxdabd[/eluser] I don't have any (yet). I just need a bit of steer of a way to do this in a MVC pattern. I would normally put a loop within a loop. Forum Categories - El Forum - 02-27-2012 [eluser]PhilTem[/eluser] Either, you do it with adjacency list or with nested sets. The queries for nested sets can be found when you google for 'joe celko nested set'. For adjacency lists it's easier. Code: function get_categories($parent_id = '0') Assuming you have a table with a column parent_id which defaults to 0 for categories and holds the ID of the parent-category for each sub-category. If you don't mind learning nested sets, then have a look at them ![]() ![]() |