Find table row where field is fully contained within searchstring

php/mysql: How can i find the table row where the field is exactly matched/contained within the search string?


search string: the cat sat on the mat
my table field is: on the mat

Have been trying field LIKE ‘%…%’ but thats not quite right?

You can look for all substrings broken up at spaces

WHERE field IN ('the cat sat on the mat', 'the cat sat on the', 'the cat sat on', 'the cat sat', 'the cat', 'the', 'cat sat on the mat', 'cat sat on the', 'cat sat on', 'cat sat', 'cat', 'sat on the mat', 'sat on the', 'sat on', 'sat', 'on the mat', 'on the', 'on', 'the mat', 'the')

The order I gave should give you the algorithm for quickly generating the list.

WHERE ‘$searchstring’ LIKE CONCAT(‘%’,table.column,‘%’)

thats worked a treat thanks r937