php mysql search feaure all keywords
Posted: Tue Aug 04, 2009 2:43 pm
Hello I have a question regarding a PHP/MySQL search feature I am trying to implement --more leaning towards mysql if thats okay..
I'm implementing a search that will either search for ALL or ANY of the keywords the user specifies, I've created PHP code that generates the following MySQL query - (i've assumed the user has searched for two words 'facebook' and 'celebrity' and the columns that are being searched are 'keywords' and 'otherkeywords'.)
select * from articles where keywords like '%facebook%' || otherkeywords like '%facebook%' or keywords like '%celebrity%' || otherkeywords like '%celebrity%'
This works for the ANY option. When I tried creating one for the ALL keywords option, i first of all assumed it would be just a case of changing the OR to AND but this is not the case it would appear as it still produces the same results as the above query.
I've tried looking on various websites but can't find an answer to this. Does anybody know a query that will produce a match for all keywords (using the example above would be fine) thanks for any help
craig
I'm implementing a search that will either search for ALL or ANY of the keywords the user specifies, I've created PHP code that generates the following MySQL query - (i've assumed the user has searched for two words 'facebook' and 'celebrity' and the columns that are being searched are 'keywords' and 'otherkeywords'.)
select * from articles where keywords like '%facebook%' || otherkeywords like '%facebook%' or keywords like '%celebrity%' || otherkeywords like '%celebrity%'
This works for the ANY option. When I tried creating one for the ALL keywords option, i first of all assumed it would be just a case of changing the OR to AND but this is not the case it would appear as it still produces the same results as the above query.
I've tried looking on various websites but can't find an answer to this. Does anybody know a query that will produce a match for all keywords (using the example above would be fine) thanks for any help
craig