![]() |
populating a dropdown list from database - 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: populating a dropdown list from database (/showthread.php?tid=47579) |
populating a dropdown list from database - El Forum - 12-14-2011 [eluser]ozy123[/eluser] Ok I am a newbie and trying to figure out how I can populate a dropdown list using the database. This is my scenario - user clicks through to a page and his userid is fed to the database which does a query and returns an array which is passed to a view to populate the dropdown (using formhelper). So Controller $options['newShift'] = $this->booking_model->get_branch($userid); Model public function get_branch($userid) {$query = $this->db->query("select idbranch from branch where uid = '$userid'"); return $query->result_array(); View <?php echo form_open('auth/new_shift') ?> <label for="branchID">Branch ID</label> <? echo form_dropdown('branchID', $newShift, set_value('branchID')); ?> However this is displaying the keys in the dropdown as well as the values (0, 1234 and 1, 2335) and then writing them to the database rather than the value. I know its such a newbie problem but I just can't figure it out. Thanks so much for any help. |