[eluser]DCZ[/eluser]
I might have an alternative for this function
(Remark the flexibility of the query could be better)
In your model or helper
Code:
function get_dropdown_array($key, $value, $from){
$result = array();
$array_keys_values = $this->db->query('select '.$key.', '.$value.' from '.$from.' order by id asc');
foreach ($array_keys_values->result() as $row)
{
$result[$row->$key]= $row->$value;
}
return $result;
}
In your controler :
Let's request some countries....
Code:
$this->data['content_countries'] = $this->my_model->get_dropdown_array('id', 'country','countries');
In your view :
Code:
<?=form_dropdown('country_id', $content_countries,$my_country_id);?>
Remark "$my_country_id" is the "selected" value on load.
We can update that last line some more.
Code:
<?=form_dropdown('country_id', $content_countries,set_value('country_id', $my_country_id))?>
So now it will select $my_country_id on first load and then it will remember it value on a failed submit.
Greetz.