php - Interdependant dropdowns dont work with uri segment but without they do in Codeigniter -


i have general question. may it's vast answer there several explanations it. beginner , can't understand it.

i have multiple interdependent dropdowns (i.e. next loads on selection of first, city, state, region, city).

in 1 of controller function work fine. (when post new listing).

i created second function same methodology used first (only difference have uri->segment in it).

now have discovered if load path second function without putting id, works fine if add .../43 (or id) second dropdown never loads.

please suggest..

controller function doesn't works

public function add_new_listing() {     $id = $this->uri->segment(3);      $this->load->model('admin/model_users');     $data['list'] = $this->model_users->getcountry();      $this->load->view('view', $data); }  public function loaddata() {     $loadtype=$_post['loadtype'];     $loadid=$_post['loadid'];      $this->load->model('admin/model_users');     $result=$this->model_users->getdata($loadtype,$loadid);     $html="";      if($result->num_rows() > 0){         foreach($result->result() $list){             $html.="<option value='".$list->id."'>".$list->name."</option>";         }     }     echo $html; } 

model:

function getcountry(){     $this->db->select('v_country_id,v_country_name');     $this->db->from('vbc_country');     $this->db->order_by('v_country_name', 'asc');      $query=$this->db->get();     return $query;  }  function getdata($loadtype,$loadid){     if($loadtype=="state"){         $fieldlist='id,v_state_name name';         $table='vbc_state';         $fieldname='country_id';         $orderbyfield='v_state_name';                            }elseif($loadtype == "region"){         $fieldlist='id,v_state_region_name name';         $table='vbc_state_region';         $fieldname='state_id';         $orderbyfield='v_state_region_name';     }else{         $fieldlist='id,v_city_name name';         $table='vbc_city';         $fieldname='state_region_id';         $orderbyfield='v_city_name';     }      $this->db->select($fieldlist);     $this->db->from($table);     $this->db->where($fieldname, $loadid);     $this->db->order_by($orderbyfield, 'asc');     $query=$this->db->get();     return $query;  } 

and view:

<select name="v_item_country" onchange="selectstate(this.options[this.selectedindex].value)"> <option value="0">select country</option>     <?php foreach($list->result() $listelement): ?>         <option value="<?= $listelement->v_country_id?>"><?= $listelement->v_country_name?></option>     <?php endforeach; ?> </select>  <select name="v_item_state" id="state_dropdown" onchange="selectregion(this.options[this.selectedindex].value)"> <option value="0">select state</option> </select>  <select name="v_item_region" id="region_dropdown" onchange="selectcity(this.options[this.selectedindex].value)"> <option value="0">select region</option> </select>  <select name="v_item_city" id="city_dropdown"> <option value="0">select city</option> </select> 

js code:

function selectstate(country_id){     if(country_id!="0"){         loaddata('state',country_id);         $("#region_dropdown").html("<option value='0'>select region</option>");     }else{         $("#state_dropdown").html("<option value='0'>select state</option>");         $("#region_dropdown").html("<option value='0'>select region</option>");     } }  function selectregion(state_id){     if(state_id!="0"){         loaddata('region',state_id);         $("#city_dropdown").html("<option value='0'>select city</option>");     }else{         $("#region_dropdown").html("<option value='0'>select region</option>");         $("#city_dropdown").html("<option value='0'>select city</option>");     } }  function selectcity(state_region_id){     if(state_region_id!="0"){         loaddata('city',state_region_id);     }else{         $("#city_dropdown").html("<option value='0'>select city</option>");     } }  function loaddata(loadtype,loadid){     var datastring = 'loadtype='+ loadtype +'&loadid='+ loadid;     $("#"+loadtype+"_loader").show();     $("#"+loadtype+"_loader").fadein(400).html('please wait... <img src="image/loading.gif" />');     $.ajax({         type: "post",         url: "loaddata",         data: datastring,         cache: false,         success: function(result){             $("#"+loadtype+"_loader").hide();             $("#"+loadtype+"_dropdown").html("<option value='0'>select "+loadtype+"</option>");               $("#"+loadtype+"_dropdown").append(result);           }     }); } 

i pretty sure public function add_new_listing() needs param loaded. try this: public function add_new_listing($param = null)


Comments