Welcome Guest, Not a member yet? Register   Sign In
Making a dropdown menu from a database
#4

[eluser]CroNiX[/eluser]
Code:
$data = $this->db->select('id, name')->get('users')->result_array();

$choices[0] = 'Select a User';  //Set a default value.  Don't use 0 if you have an ID of 0 in the db.

//array that form_dropdown() needs has to be in format of (id => name)
//where id is the value that will get sent with the form and name is what is shown in the text of the option
foreach($data as $d)
{
  $choices[$d['id']] = $d['name'];
}

echo form_dropdown('users', $choices, set_value('users', 0));


Messages In This Thread
Making a dropdown menu from a database - by El Forum - 06-26-2012, 06:34 AM
Making a dropdown menu from a database - by El Forum - 06-26-2012, 07:03 AM
Making a dropdown menu from a database - by El Forum - 06-26-2012, 07:39 AM
Making a dropdown menu from a database - by El Forum - 06-26-2012, 04:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB