add round brackets around your or statements (problem of operator precedence)
where
(`tags` LIKE '$keywords %' OR `tags` LIKE '% $keywords %' OR `tags` LIKE '% $keywords'")
AND `city` = '".$city."'
문제
Among my DB columns there are the columns "tags" and "city". Because I need the search of exact words I'm using LIKE %
a few times in the WHERE
clause i.e.
SELECT ... WHERE `tags` LIKE '$keywords %' OR `tags` LIKE '% $keywords %' OR `tags` LIKE '% $keywords'"
It works good but if I added AND city='".$city."'
to WHERE
clause the SQL ignores this and I get all results for keywords (tags) even if I selected specific city that is no in any row of the DB column "city".
해결책
add round brackets around your or statements (problem of operator precedence)
where
(`tags` LIKE '$keywords %' OR `tags` LIKE '% $keywords %' OR `tags` LIKE '% $keywords'")
AND `city` = '".$city."'