Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save amad4biz/6453cdca1b2f59b79a85a5b5365f17a1 to your computer and use it in GitHub Desktop.

Select an option

Save amad4biz/6453cdca1b2f59b79a85a5b5365f17a1 to your computer and use it in GitHub Desktop.
//needs jquery and jquery-ui
// auto complete
$( "#autocomplete-cities" ).autocomplete({
source: function(request, response) {
//console.info(request, 'request');
//console.info(response, 'response');
$.ajax({
//q: request.term,
url: "<?=site_url('geo/suggested_cities')?>",
data: { term: $("#autocomplete-cities").val()},
dataType: "json",
type: "POST",
success: function(data) {
//console.info(data);
response(data);
}
});
},
minLength: 2
});
<?PHP
function suggested_cities()
{
$term = $this->input->post('term');
$query = "SELECT id,accent_city FROM {$this->tbl_geo} WHERE accent_city LIKE '{$term}%' LIMIT 10";
$cities_data = $this->crud->run_query($query);
$cities = array();
foreach($cities_data->result_array() as $key):
$a = array(
'id' => trim($key['id']),
'label' => trim($key['accent_city']),
'value' => trim($key['accent_city'])
);
$cities[] = $a;
endforeach;
echo json_encode($cities);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment