CodeIgniter Forums
An idea for foreach - 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: An idea for foreach (/showthread.php?tid=52324)



An idea for foreach - El Forum - 06-06-2012

[eluser]Gabi3xz[/eluser]
I have form dropdown with the results of foreach.
Code:
foreach ($result_cat->result() as $row):
       echo form_dropdown($row->id, $row->cat_name);
endforeach;
Problem is that multiply and form_dropdown for each result.
how do I set up correctly?


An idea for foreach - El Forum - 06-06-2012

[eluser]sanir[/eluser]
try this code.

Code:
foreach ($result_cat->result() as $row):
  $data[$row->id] = $row->cat_name;
      
endforeach;
echo form_dropdown($data);