codeigniter - Code Igniter - form_dropdown selecting correct value from the database -


im having few problems form_dropdown function in codeigniter .... application in 2 parts, user goes in, enters form , submits .... once submitted admin can go in , edit persons form , save database.

so, display dropdown in initial form, im using following ( options in dropdown coming 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() $row){             $return[$row['id']] = $row['salaryrange'];         }     }     return $return; } 

then in controller:

$data['salaries'] = $this->salary_expectation->get_salaries_dropdown(); 

then view:

<?php echo form_dropdown('salaries', $salaries, set_value('salaries', $salaries));  ?> 

that bit works perfect in displaying dropdown filled values user select.

so, when user selects value, hits save, saved database.

on edit page admin see's, im using same code display dropdown filled options, how automatically choose 1 thats been selected user in initial stage?

cheers,

according codeigniter documentation

the first parameter contain name of field, second parameter contain associative array of options, , third parameter contain value wish selected. can pass array of multiple items through third parameter, , codeigniter create multiple select you.

your admin controller should have like

$data['selected'] = $this->salary_expectation->get_salary_selected(); 

according this, admin view should this

<?php echo form_dropdown('salaries', $salaries, $selected_value);  ?> 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -