HMShingala

Country State City Flow In Codeigniter Using Jquery Ajax


My Controller’s Function Code:-
                //STATE
public function state($id)
  {
$this->load->model(‘admin/model’);
$where=array(“country_id”=>$id);
//print_r ($where); break;
  $state=$this->model->sel_where(‘state’,$where);
 echo “-State-“;
 foreach($state as $row)
 {
echo””.$row[‘state_name’].””;  
 }
}
//city
public function city($id)
  {
$this->load->model(‘admin/model’);
$where=array(“state_id”=>$id);
//print_r ($where); break;
  $city=$this->model->sel_where(‘city’,$where);
 echo “-City-“;
 foreach($city as $ct)
 {
echo””.$ct[‘city_name’].””;  
 }
}
My Model’s Function Code:-
//select data with id  
public function sel_where($tbl,$where)
{
$r=$this->db->get_where($tbl,$where);
$rr= $r->result_array();
//print_r($rr);break;
return $rr;
}
My View’s Html Code:-
    
var state,city;
function change_state()
{
state=$(‘#country_id’).val();
$(‘#state_id’).load(‘index.php/admin/user/state/’+state);
}
function change_city()
{
city=$(‘#state_id’).val();
$(‘#city_id’).load(‘index.php/admin/user/city/’+city);
}
Select Country
    Country
          <?php foreach($cnt as $c)
 { ?>
          <option value="”>
  Select State
   
       -State-
       
       Select City
             
               -city-
           

One Response

  1. Good Working harshit keep it up dude

    can u send me more code like this type of ajax scri[ts
    please

    – hemali patil

Leave a Reply

Your email address will not be published. Required fields are marked *

one + 20 =