![]() |
Help: Using dropdown form helper with an Array from model - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Help: Using dropdown form helper with an Array from model (/showthread.php?tid=12342) |
Help: Using dropdown form helper with an Array from model - El Forum - 10-15-2008 [eluser]rt30000[/eluser] I have figured out how to do this the manual way (creating my own helper function), but I would really like to use the built in CI forms helper for the dropdown. Here is a sample of how I would like to use it... Code: <?php echo form_dropdown('dessert', $recipes['dessert'], '', $js);?> The $recipes['dessert'] is an array that contains the 'id' and 'recipe_title' for multiple items. It's my understanding that this should work, I am not sure why it does not. Here is a print_r(); of my $recipes['dessert'] array (two items): Code: Array ( I can loop through the array fine, so why is it not working in the CI form_dropdownCI form_dropdown(); function? You can view the page HERE. Thanks so much for shedding any light on this. Rob Help: Using dropdown form helper with an Array from model - El Forum - 10-15-2008 [eluser]Bogdan Tanase[/eluser] array that is passed to dropdown should look like this: Code: $recipes['desert']=array(26=>'Angel Food Cake', a single dimensional array with key and value. Help: Using dropdown form helper with an Array from model - El Forum - 10-16-2008 [eluser]rt30000[/eluser] I have some reading up to do with php's mysql functions and how to return them. Here is the code I have in my model, how can I return this as a single dimensional array with key and value as you suggest? Code: $this->db->select('id, recipe_title'); Help: Using dropdown form helper with an Array from model - El Forum - 10-16-2008 [eluser]xwero[/eluser] Code: if ($query->num_rows() > 0) edit : changed code inside of the loop because it was not working. Help: Using dropdown form helper with an Array from model - El Forum - 10-16-2008 [eluser]rt30000[/eluser] I ended up finding an old post after searching for 'single dimensional array', which JUST led me to creating the following solution... Code: if ($query->num_rows() > 0) Thanks so much everyone (especially xwero, you seem to help on every post I make!). One more issue resolved! I am beginning to love CI. |