CodeIgniter Forums
How to make searchbox work with multiple fields - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Best Practices (https://forum.codeigniter.com/forumdisplay.php?fid=12)
+--- Thread: How to make searchbox work with multiple fields (/showthread.php?tid=79297)



How to make searchbox work with multiple fields - Lipe_Bogaci - 05-25-2021

Hi CI lovers
how can i make one search box with multiple fields?


RE: How to make searchbox work with multiple fields - includebeer - 05-25-2021

Do you mean one text input field to search in multiple columns? If so you can use like() and orLike() in your query.
PHP Code:
  $this->yourModel
        
->like('title'$searchText)
        ->orLike('description'$searchText)
        ->orLike('comment'$searchText); 

I have an example of that in this article: https://includebeer.com/en/blog/how-to-build-a-basic-web-application-with-codeigniter-4-part-5