Showing data in a loop, view, controller, model - 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: Showing data in a loop, view, controller, model (/showthread.php?tid=43812) |
Showing data in a loop, view, controller, model - El Forum - 07-24-2011 [eluser]blitzneo[/eluser] I have a simple database, with 2 tables. One for brand, the other for model, having cars as examples. In my model I have 2 functions, one to get all brands, and one to get all models from a brand. This way: Code: public function get_brands() Both working perfectly, so my question is, how can I get in a view something like brand-1: - model1 - model2 - model3 brand-2: - model1 - model2 etc. Sorry if it is a too easy question, but I am just trying to learn. I am using a foreach loop btw. This is the view. Code: BRANDS: Any help will be great =) Thanks for your time Showing data in a loop, view, controller, model - El Forum - 07-24-2011 [eluser]SitesByJoe[/eluser] You need to do something like this: Code: <?php Showing data in a loop, view, controller, model - El Forum - 07-24-2011 [eluser]SitesByJoe[/eluser] And you don't need the result() portion of my snippet. Showing data in a loop, view, controller, model - El Forum - 07-24-2011 [eluser]blitzneo[/eluser] Code: <?php "Invalid argument supplied for foreach()" It cannot be merged like you commented or am I missing something ? Thanks! Showing data in a loop, view, controller, model - El Forum - 07-24-2011 [eluser]shailendra[/eluser] Please check this link http://ellislab.com/forums/viewthread/193763/#916973 Showing data in a loop, view, controller, model - El Forum - 07-25-2011 [eluser]blitzneo[/eluser] Thanks a lot, I am having a look at it =) Showing data in a loop, view, controller, model - El Forum - 07-25-2011 [eluser]SitesByJoe[/eluser] Try this code: Code: $brands = $this->db->get('brands'); Showing data in a loop, view, controller, model - El Forum - 07-26-2011 [eluser]blitzneo[/eluser] Very interesting post =) I will be using Joe's suggestion for now. I will check performance in a future 'upgrade' of the webapp. Thanks guys. |