![]() |
How to loop the $data in a view/template? - 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: How to loop the $data in a view/template? (/showthread.php?tid=5411) |
How to loop the $data in a view/template? - El Forum - 01-21-2008 [eluser]agartzia[/eluser] Hi there! I've just discovered CI and I think it's amazing! I need to loop inside a template all along the array. The structure is as shown: Code: $data[0][id] = 1 And so on... The problem would be solved if I could iterate the array, but CI gives me the keys instead of the array itself, which is not very useful for me. I've thought I might add a key... Code: $this->load->view('body', array('main_data' => $data)); Is there a way to access the $data itself? Thanks! Keep it on! How to loop the $data in a view/template? - El Forum - 01-21-2008 [eluser]xwero[/eluser] You are on the good path. In your view you do something like this Code: <?php foreach(main_data as $member){ ?> How to loop the $data in a view/template? - El Forum - 01-21-2008 [eluser]agartzia[/eluser] I don't think I have it... main_data isn't defined, neither as variable nor as constant. Another hint? Can I access it without using it another array? How to loop the $data in a view/template? - El Forum - 01-21-2008 [eluser]xwero[/eluser] there is a mistake in my previous snippet Code: <?php foreach($main_data as $member){ ?> How to loop the $data in a view/template? - El Forum - 01-22-2008 [eluser]agartzia[/eluser] Thanks, but it's not what I'm looking for. I gotta make the Code: $this->load->view('body', array('main_data' => $data)); Thanks! How to loop the $data in a view/template? - El Forum - 01-22-2008 [eluser]dawnerd[/eluser] You are right. Do it that way and it should work like a charm. How to loop the $data in a view/template? - El Forum - 01-22-2008 [eluser]xwero[/eluser] [quote author="agartzia" date="1201005938"] I gotta make the Code: $this->load->view('body', array('main_data' => $data)); [/quote] you can use Code: $body['main_data'] = $data; How to loop the $data in a view/template? - El Forum - 01-22-2008 [eluser]agartzia[/eluser] OK, thanks for your help! |