![]() |
object to array as in db - 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: object to array as in db (/showthread.php?tid=55440) |
object to array as in db - El Forum - 10-26-2012 [eluser]Pana_Ruplahlava[/eluser] Ok, here is the situation. I can do it in php easily and i repeat it often, so there must be an easy way to do it in CI, but i dont know how. I started using it yesterday. So: in db i have field id and field label and i need it put it into select. as id as value and label as text. in past 2 hours in user guide i was not able to figure it out. i assume i have to put it in array so form_dropdown can use it. but how. there must be an easy way... anybody can help? ![]() this is what i was able to get from DB ![]() Code: Array and i need it looking like Code: Array Thx for any help ![]() object to array as in db - El Forum - 10-26-2012 [eluser]CroNiX[/eluser] You just have to format it. Code: $options = array(); Now $options is in the format needed for form_dropdown(). Code: Array( object to array as in db - El Forum - 10-26-2012 [eluser]Pana_Ruplahlava[/eluser] Thanks, i had it this way, but my experience with CI is just amazing so i expected something like Code: do_magic_assign($array,'id','label'); Thanks a lot ![]() object to array as in db - El Forum - 10-26-2012 [eluser]CroNiX[/eluser] I created a helper, array_to_dropdown($array, $key_field, $value_field, $default = array()), that does that, as well as create an optional default first value, "Choose City" or whatever. Maybe I should submit it, although it's pretty simple like you showed. |