Welcome Guest, Not a member yet? Register   Sign In
populating a dropdown list from database
#1

[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>
&lt;?
echo form_dropdown('branchID', $newShift, set_value('branchID'));
?&gt;

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.




Theme © iAndrew 2016 - Forum software by © MyBB