문제

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."' 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top