I have written some code to make a search in the CODEIGNITER3 framework. When I insert 2 or more words to search input, it works great, however, when I enter just 1 word, it gives this error.
How can I solve this problem? Here is my controller:
function search() {
$keyword = strip_tags($this->input->get('searchforcourses'));
$keyword = explode(" ", $keyword);
$data['title'] = 'Bütün Kurslar Burada';
$data['courses'] = $this->courses_model->courses_search($keyword);
$this->load->view('templates/header');
$this->load->view('courses/courses', $data);
$this->load->view('templates/footer');
}
And here is my model:
function courses_search($keyword) {
$this->db->select('*');
$this->db->from('courses');
$this->db->like('title',$keyword[0]);
$this->db->or_like('title',$keyword[1]);
$this->db->join('instructors', 'instructors.id = courses.instructor_id', 'left');
$this->db->join('categories', 'categories.id = courses.category_id', 'left');
$query = $this->db->get();
return $query->result_array();
}
Thanks in advance!