how can i use a single jquery autocomplete for multiple form dropdown?
here is my view page(header):
$("#full_name").autocomplete({
source: "<?php echo site_url('autocomplete/get_names');?>"
});
$("#department").autocomplete({
source: "<?php echo site_url('autocomplete/get_dept');?>"
});
*** and other like these for subjects, zip and country.
controller page:
public function get_names(){
$this->load->model('autocomplete_model');
if (isset($_GET['term'])){
$q = strtolower($_GET['term']);
$this->autocomplete_model->get_fullnames($q);
}
}
*** and other functions...
model page:
function get_fullnames($q)
{
$match = $q;
$this->db->select('full_name');
$this->db->like('full_name', $match,'after');
$query = $this->db->get('employee_list');
if($query->num_rows > 0){
foreach ($query->result_array() as $row){
$row_set[] = htmlentities(stripslashes($row['full_name']));
}
echo json_encode($row_set);
}
}
how can i implement a single search term that could be used for multiple criteria?
thank you guys in advance..
This is not going to scale; as your database tables grow, this implementation will become very sluggish. What you need to do is use an indexing engine to allow Full Text Searching.
MySQL does not allow Full Text Search on InnoDB tables (actually, it was just released in the latest version, but it’s still in it’s infancy). Look into using Elastic Search, Sphinx, or Solr.
Poke around StackOverflow to find the best engine for you – there are many helpful questions that have been asked in the past regarding this problem. Hopefully that sets you on the right course.