dropdown problem |
[eluser]crwtrue[/eluser]
i have a form with dropdown which is filled with items gotten from sql-query. I also want a no item option in dropdown and i used array_push to insert the no item option but it dont work. Any ideas? i am using form helper.
[eluser]bretticus[/eluser]
Shouldn't you be prepending to the front of the array? See array_unshift. Also, if you have arrays in an array, you can use the array_merge function to build a new array. Code: $records = array(array('id'=>1, 'name'=>'bob'), array('id'=>2, 'name'=>'alice'));
[eluser]Johan André[/eluser]
I use this in my models (usually in MY_Model and then extend my models from it): Code: // <option value="$key">$value</option>
[eluser]joeizang[/eluser]
hey guys, thought I should chip in here hope this helps, active record creates multi-dimensional array when you fetch results, and when you want to make a drop down menu in the view it expects a flat array so why not just do your normal pulling of data and say in the model you have $data = array(); $result = $this->db->get('tablename'); if($result->num_rows()>0) { foreach( $result->result_array() as $row) { $data[$row['columnname']] = $row['anothercolumnname']; } } this worked for me though so don't know if this is helpful. |
Welcome Guest, Not a member yet? Register Sign In |