1

i have written a method and model for keyword search. But unfortunately I am getting the output which are matched with my keyword and also which does not have any match with the keyword I typed.

Here is My Code:

controller.php :

       function suggestions()
{
        $this->load->model('Booksmodel');
        $term = $this->input->post('term',TRUE); 
        $rows = $this->Booksmodel->GetAutocomplete(array('keyword' => $term)); 
        $json_array = array();
        foreach ($rows as $row) 
        array_push($json_array, $row->book_title);
        array_push($json_array, $row->auth_firstname);
        array_push($json_array, $row->isbn);  

        echo json_encode($json_array);
}

Please help me.

4

1 回答 1

1

试试这个(在函数中添加了另一个参数,无'like'):

 function GetAutocomplete($options = array())
  { 
    $this->load->database();   
    $this->db->limit('10');  
    $this->db->select('book_title,auth_firstname,isbn,auth_lastname,publisher_name');    
    $this->db->like('book_title', $options['keyword'], 'none');
    $this->db->or_like('auth_firstname', $options['keyword'], 'none'); 
    $this->db->or_like('isbn', $options['keyword'], 'none');
    $this->db->or_like('auth_lastname', $options['keyword'], 'none');
    $this->db->or_like('publisher_name', $options['keyword'], 'none'); 

    $query = $this->db->get('bookdetails');
      return $query->result();
    } 

'none' 将阻止它%在类似函数中使用通配符 ( )。

于 2013-03-08T06:44:59.767 回答