1

キーワード検索の方法とモデルを書きました。しかし、残念ながら、キーワードと一致し、入力したキーワードと一致しない出力が表示されます。

これが私のコードです:

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

私を助けてください。

4

1 に答える 1

1

これを試してください( function に別のパラメーター none を追加しました'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' を指定すると%、like 関数でワイルドカード ( ) を使用できなくなります。

于 2013-03-08T06:44:59.767 に答える