我正在为我的书店项目创建CodeIgniter搜索。单个单词搜索是可以的,但是当我使用多个单词搜索时,我会遇到问题。我该如何解决此问题。
我的控制器
public function search()
{
/*=== LOAD DYNAMIC CATAGORY ===*/
$this->load->model('admin_model');
$view['category'] = $this->admin_model->get_category();
/*==============================*/
$this->form_validation->set_rules('search_book', "Search",'required');
if($this->form_validation->run() == FALSE)
{
#...Redirected same page after action
redirect($_SERVER['HTTP_REFERER']);
}
else
{
$query = $this->input->post('search_book');
$this->load->model('user_model');
$view['books'] = $this->user_model->search($query);
$view['user_view'] = "users/search_books";
$this->load->view('layouts/user_layout', $view);
}
}
我的模特
public function search($query)
{
$this->db->order_by('id', 'DESC');
$this->db->from('books');
$this->db->like('book_name', $query);
$this->db->where('status', 1);
$q = $this->db->get();
return $q->result();
}
就像我在搜索框中编写PHP一样,它带走了我所有带有PHP字样的书。对我来说还可以。
但是,当我在搜索框中编写PHP BOOKS时,显示没有找到书。
如果要匹配任何单词,我希望它显示结果。
慕婉清6462132