I have simple database query in codeigniter, however I cannot get search to work with wildcard. This is my code:
$this->db->like('film.title',"%$query%"); $this->db->escape_like_str($query); $res = $this->db->get('film');
If I remove wildcard(%) then search works fine. Also $query is just string with user input. Any help is appreciated.
Advertisement
Answer
$this->db->like()
automatically adds the %s and escapes the string. So all you need is
$this->db->like('title', $query); $res = $this->db->get('film');