I am not going to teach you how to create a search form or how to clean your inputs in this tutorial. I assume you have some knowledge of how to do that or you can try a search through our tutorial database. This tutorial will teach you how to search Mysql effectively without using tons of extra coding.
Most people know you can use LIKE %$search% to find matches but what if your user input "Pirates Action" with the hopes of finding an action movie that may have Pirates in them? Well this tutorial shows you how to separate the phrase and search for both words.
Steps :
At this point you would have already created your php file that will get the search phrase. In this example I will assume that your search field is named "search" and that you have sanitized the input.
This is the fun part and the part that makes this work. We need to explode the spaces in the phrase and place them in an array. We can then use "OR" for each word other than the first. In this example we want to match the column "title" with our search phrase. You can use any column.
The final step is now to place the "$wsearch" within the sql and it will do the rest. The complete code below.
That's it!! Post a comment if you have any questions or changes.