Como hace, este archivo es cargar la librería de jquery para poder utilizar ajax y el código jquery donde diremos que cuando el select con id country cambie de opción, en el evento change
table pp_countries
------------------
id
country_name
table pp_cities
---------------
id
country_ID
city_name
El controlador home.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Home extends CI_Controller {
public function __construct(){
parent::__construct();
$this->ads = '';
$this->ads = $this->ads_model->get_ads();
}
public function index()
{
//Comuna
$data['cities_res'] = $this->cities_model->get_all_cities();
//Cuidad
$data['country_res'] = $this->countries_model->get_all_countries();
$this->load->view('home_view',$data);
}
}
el modelo cities_model.php
public function get_all_cities($id) {
$this->db->select('*');
$this->db->from('pp_cities');
$this->db->order_by("sort_order", "ASC");
$this->db->order_by("city_name", "ASC");
$Q = $this->db->get();
if ($Q->num_rows > 0) {
$return = $Q->result();
} else {
$return = 0;
}
$Q->free_result();
return $return;
}
el modelo countries_model.php
public function get_all_countries() {
$this->db->select('*');
$this->db->from('pp_countries');
$this->db->order_by("id", "ASC");
$Q = $this->db->get();
if ($Q->num_rows > 0) {
$return = $Q->result();
} else {
$return = 0;
}
$Q->free_result();
return $return;
}
la vista home_search.php
<?php echo form_open_multipart('buscador/search',array('name' => 'jsearch', 'id' => 'jsearch'));?>
<div class="col-md-4">
<!--<input type="text" required name="job_params" id="job_params" class="form-control" placeholder="Job title or Skill" />-->
<select class="form-control" name="jcountry" id="jcountry">
<option value="" selected>Select City</option>
<?php if($country_res): foreach($country_res as $country):?>
<option value="<?php echo $country->country_name;?>"><?php echo $country->country_name;?></option>
<?php endforeach; endif;?>
</select>
</div>
<div class="col-md-4">
<select class="form-control" name="jcity" id="jcity">
<option value="" selected>Select City</option>
<?php if($cities_res): foreach($cities_res as $cities):?>
<option value="<?php echo $cities->city_name;?>"><?php echo $cities->city_name;?></option>
<?php endforeach; endif;?>
</select>
</div>
<div class="col-md-2">
<input type="submit" name="job_submit" class="btn" id="job_submit" value="Search" />
</div>
<?php echo form_close();?>