简体   繁体   中英

Ajax, input for searching rows in table, live search

user types something in input, it calls ajax defining it to go on some function in controller. then according to that input it should short list the table rows, matching it with 2 or 3 columns of that database. i have working code of this in simple php. which calls ajax and display the output from another page that ajax calls in the script. but i need it to work in codeigniter. i'm not sure how will i get this working. Any help or advice? this is the function that ajax calls on input change. i've tried to convert my simple php working page code into codeigniter. + i'm calling brandlookup1 which is another page then my current page. any syntax error or best practice? for this kind of issues.

You should try this:

In Controller

function fetch_brands(){
  $search = $this->input->post('query');
  $data['record1] = $this->Model_Name->Function_Name($search);
}

In Model

function Function_Name($search){
  $this->load->database();
  $search = $this->db->escape_str($search);
  $sql = 'select * from brand where brand like "%'.$search.'%" OR description like "%'.$search.'%" OR status like "%'.$search.'%"';

  $query = $this->db->query($sql); 
  return $query->result();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM