My users put search terms in an input field. The script I’m using stores that in a $find variable. It then searches mysql like so:
"select * from mytable WHERE title LIKE '%$find%' or description LIKE '%$find%'";
I want to be able to pull a result, even if 1 word is in the title and another in the description, which currently doesn’t happen. So.. I’m guessing I need to break the $find variable into an array with a function. After that, how would I do the search in mysql? Since I never know how many words will be in the search (they might decide to search for 8 words at once), how do I reference the array in the mysql query?
Thx in advance!
You should use a FULLTEXT index and build a proper boolean search query on it.
You MAY achieve the effect you want without it, but this would be very slow compared to using FULLTEXT index. You would have to use
explodeto get the list of words, then build aWHEREcondition likeconcat(title, description) LIKE '%word1%' AND concat(title, description) LIKE '%word2%'etc.(In my first answer I stated that achieving this effect is impossible without FULLTEXT. I was wrong and edited this answer.)