Ajax,用于在表中搜索行的输入,实时搜索

时间:2017-09-07 07:27:30

标签: javascript php jquery ajax codeigniter

用户在输入中键入内容,它调用ajax定义它以继续执行控制器中的某些功能。然后根据该输入,它应该列出表行,将其与该数据库的2或3列匹配。我有简单的PHP工作代码。它调用ajax并显示ajax在脚本中调用的另一个页面的输出。但我需要它在codeigniter中工作。我不确定如何才能使这个工作。任何帮助或建议?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.

1 个答案:

答案 0 :(得分:0)

你应该试试这个:

在控制器中

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

在模型中

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();
}