![]() |
Fill dropdown with an option array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Fill dropdown with an option array (/showthread.php?tid=54008) |
Fill dropdown with an option array - El Forum - 08-18-2012 [eluser]Tenter[/eluser] Hello, I have a problem with my code.. i cant figure out how to get it work.. The problem is that i have this array wich i get from my model: Code: public function get_all_dansetyper() Afterwards i use this get funktion in my controller: Code: public function index() And this variable "dansetyper" ill send to my view file with the array in, this array is an object and i cant just put it into my: Code: <php the $options now contain a string with Code: string 'array('1' => 'Folkedans', '2' => 'Selskabsdans', '3' => 'Linedans', );' (length=70) My question is, How do i fill my form_dropdown with information from my sql array?? Fill dropdown with an option array - El Forum - 08-18-2012 [eluser]srpurdy[/eluser] Code: $data = array(); But you may also move ->result_array() into your model function. Fill dropdown with an option array - El Forum - 08-18-2012 [eluser]Tenter[/eluser] I have to send it Code: <?php echo form_dropdown('dansetype', $options, 'large');?> so the $option is the array ? But i got this Code: Fatal error: Call to a member function result_array() on a non-object Fill dropdown with an option array - El Forum - 08-18-2012 [eluser]Tenter[/eluser] how do i move it and where to place it ? im pretty new to codeigniter.. so plz help ![]() Fill dropdown with an option array - El Forum - 08-18-2012 [eluser]srpurdy[/eluser] Hi Tenter, First change. Code: return $result->result(); to Code: return $result; replace Code: <php with Code: $data = array(); Fill dropdown with an option array - El Forum - 08-18-2012 [eluser]Tenter[/eluser] It worked ! Ty m8 that was awesome ![]() my dropdown list is now filled with options from my array from the database ![]() Fill dropdown with an option array - El Forum - 08-18-2012 [eluser]srpurdy[/eluser] ![]() ![]() Fill dropdown with an option array - El Forum - 10-25-2012 [eluser]AlanW[/eluser] I have also achieved the drop down filled with options from my array from the database but when I use $c_level = $this->input->post('c_level'); it comes back to my controller as an index integer, not the actual text that was in my drop down. How do you fix this ? Fill dropdown with an option array - El Forum - 10-25-2012 [eluser]CroNiX[/eluser] Code: $dropdown = array( When the form is sent, it is the 'key' that is sent. The 'option text' is what is displayed. The above would produce: Code: <option value="key">option text</option> So if you want the text sent with the form, you need to put that as the 'key' in the above example, although I'm not sure why you wouldn't just send the key (id) like you currently are instead of the text. |