I am trying to populate dropdown with database what i am actually trying to do i have 3 drop downs country ,state and city and i want if user select any country crossponding states are shown in dropdown and crossponding cities releated to state are shown in city dropdown.I don't how to achieve this all fields will be saved in tabl_usrs and and i have nm_country,nm_state and nm_city table from where country states and cities are shown in tabl_usrs i have country,state and city field wwhich act as foriegn key??
any links will be welcome.Hope any one can help.below is just i am trying to do this seprate from project
Controller
$data['city_list'] = $this->City_model->get_dropdown_list();
$this->load->view('my_view_file', $data);
Model
function get_dropdown_list()
{
$this->db->from('city');
$this->db->order_by('name');
$result = $this->db->get();
$return = array();
if($result->num_rows() > 0) {
foreach($result->result_array() as $row) {
$return[$row['id']] = $row['name'];
}
}
return $return;
}
View
<?php echo form_dropdown('city_id', $city_list, set_value('city_id', $city_id));