needle in haystack search
Posted: Fri Sep 09, 2011 5:13 pm
Hi, I'm trying to implement a search on a database where the column needs to match part of a string (ie needle in haystack) however all the examples I can find have the haystack as the column in database and the needle as the string resolved by
or something like that.
I need it in reverse - ie the column as needle and the string as haystack. I have tried
for example I have a list of cities in database and someone types city and country - someone types
If anyone can give me any ideas to match 'new york usa' or 'long city name the federal republic of wherever' etc etc that would be great. like strpos in php.
Code: Select all
WHERE `column` LIKE '%{$needle}%'I need it in reverse - ie the column as needle and the string as haystack. I have tried
but get problems.column IN (string)
for example I have a list of cities in database and someone types city and country - someone types
which I need to match to a column with just new york. I have tried breaking it up which works with simpler examplesnew york usa
but that gets more complicated when you create'london', 'england'
then I can't match new york.'new', 'york', 'usa'
If anyone can give me any ideas to match 'new york usa' or 'long city name the federal republic of wherever' etc etc that would be great. like strpos in php.