Let’s say i check if
$strig = "how can i do this";
already exists in my database with all words order options?
Like:
“how i can do this”
or
“i do this can how”
…
…
my database looks like:
id string
1 how can i do this
2 hello how are you
3 how i can do this world
4 another title
etc etc
Thanks
This is a tricky problem if you want to fix this in sql only, but that aside:
As @er.anuragjain says, you can do a query with
LIKE %word%, but you would also get a hit on your example ‘3’.So if you have a query like this:
Then you also get number 3. So you need to check if there are no other words. You can do this by checking the word count (if you have 5 words and all of your words are in there, you are done.).
Checking wordcount is not trivial, but there is a trick. From several sources*:
should do the trick. So check the
LIKE‘s, and check the wordcount, and you’re done. But I’m not really sure this is a pretty sollution 🙂and http://www.mwasif.com/2008/12/count-number-of-words-in-a-mysql-column/
(random google hits 🙂 )