Reputation: 163
I am trying to write a sql statement that can pull a unique record by comparing it's different variations
For example, I have a unique record of a movie let's say Bad Boys II.
But users do search for;
bad boys 2
badboys2 >
badboys II (2003)
bad boys 2 (2003)
etc.
.... LOWER(movie_title) LIKE '%$search_query%'
The above query does not return the unique record i was hoping to get. Any help will be appreciated
Upvotes: 2
Views: 714
Reputation: 67
You can do the following:
1) Put the words from the string in an array
2) Look for a match with each word:
SELECT * FROM table WHERE LOWER(movie_title) LIKE '%$search_words[$i]%'
Howether, if you search for "bad booys 2" for example with this code you will get all movies which contain the words "bad", "boys" and 2.
Upvotes: 1