1

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

例えば。著者の名前として「grisham」のようなキーワードを入力するとbook_title,auth_firstname,isbn、「grisham」(つまりauth_lastname) を含む他のすべてのデータ()が出力として取得されます。

*ただし、入力したキーワードは、author_lastnameとのみ一致します。では、なぜ他の名前が表示されるのですか?* aUth_last名のみを表示する必要がありますか?

私の問題を解決するために、私を助けてください。

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);
        array_push($json_array, $row->auth_lastname);
        array_push($json_array, $row->publisher_name); 

        echo json_encode($json_array);
}

model.php

 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']);
    $this->db->or_like('auth_firstname', $options['keyword']); 
    $this->db->or_like('isbn', $options['keyword']);
    $this->db->or_like('auth_lastname', $options['keyword']);
    $this->db->or_like('publisher_name', $options['keyword']); 

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

0 に答える 0