As it does, this file is to load the library of jquery to be able to use ajax and the jquery code where we will say that when the select with id country changes of option, in the change event
table pp_countries
------------------
id
country_name
table pp_cities
---------------
id
country_ID
city_name
The home.php driver
<?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);
}
}
the model 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;
}
the countries_model.php model
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;
}
the view 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();?>