1

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".

stckvrw
  • 1,689
  • 18
  • 42

1 Answers1

1

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."' 
Raphaël Althaus
  • 59,727
  • 6
  • 96
  • 122