Im having a few problems with the form_dropdown function in CodeIgniter .... My application is in 2 parts, a user goes in, enters a form and submits it .... once its submitted a admin can go in and edit that persons form and then save it to database.
So, to display the dropdown in the initial form, im using the following ( all the options in the dropdown are coming from the database )
Model:
function get_salaries_dropdown() { $this->db->from($this->table_name); $this->db->order_by('id'); $result = $this->db->get(); $return = array(); if($result->num_rows() > 0){ $return[''] = 'please select'; foreach($result->result_array() as $row){ $return[$row['id']] = $row['salaryrange']; } } return $return; } Then in the Controller:
$data['salaries'] = $this->salary_expectation->get_salaries_dropdown(); Then finally the View:
<?php echo form_dropdown('salaries', $salaries, set_value('salaries', $salaries)); ?> That bit works perfect in displaying the dropdown filled with values for the user to select.
So, when the user selects a value, then hits save, its saved to the database.
On the Edit page which the admin see's, im using the same code to display the dropdown filled with options, but how do i get it to automatically choose the one thats been selected by the user in the initial stage?
Cheers,
The first parameter will contain the name of the field, the second parameter will contain an associative array of options, and the third parameter will contain the value you wish to be selected.What is thisset_valuemethod you are using in third parameter?