Php Mysql在使用AND&;时排除第一个参数;还是在同一个查询中?
我正在尝试执行这个非常简单的查询 links\u public 1=show 链接\u public 0=不显示 但是,当运行下面的查询时,它仍然返回链接设置为0的所有行Php Mysql在使用AND&;时排除第一个参数;还是在同一个查询中?,php,mysql,Php,Mysql,我正在尝试执行这个非常简单的查询 links\u public 1=show 链接\u public 0=不显示 但是,当运行下面的查询时,它仍然返回链接设置为0的所有行 SELECT * FROM links WHERE links_public = '1' AND links_description LIKE '%$filter%' OR links_created_by LIKE '%$filter%' OR links_link LIKE '%$filter%' ORDER
SELECT *
FROM links
WHERE links_public = '1'
AND links_description LIKE '%$filter%'
OR links_created_by LIKE '%$filter%'
OR links_link LIKE '%$filter%'
ORDER BY links_created DESC
改变
SELECT *
FROM links
WHERE links_public = '1'
AND links_description LIKE '%$filter%'
OR links_created_by LIKE '%$filter%'
OR links_link LIKE '%$filter%'
ORDER BY links_created DESC
到
尝试使用一些括号 差不多
SELECT *
FROM links
WHERE links_public = '1'
AND (links_description LIKE '%$filter%'
OR links_created_by LIKE '%$filter%'
OR links_link LIKE '%$filter%')
ORDER BY links_created DESC
从你拥有它的方式来看,它被视为
SELECT *
FROM links
WHERE (links_public = '1'
AND links_description LIKE '%$filter%')
OR links_created_by LIKE '%$filter%'
OR links_link LIKE '%$filter%'
ORDER BY links_created DESC
查看一下将括号放在周围,然后尝试:
SELECT *
FROM links
WHERE (links_public = '1')
AND (links_description LIKE '%$filter%'
OR links_created_by LIKE '%$filter%'
OR links_link LIKE '%$filter%')
ORDER BY links_created DESC
OR正在产生问题。您需要使用()对条件进行分组。你应使用:-
SELECT *
FROM links
WHERE links_public = '1'
AND (links_description LIKE '%$filter%'
OR links_created_by LIKE '%$filter%' OR links_link LIKE '%$filter%' )
ORDER BY links_created DESC
也许你应该添加一些()来确定优先级。OR正在制造一个问题。当没有评论就被否决时,总是感觉很糟糕。请评论!!
SELECT *
FROM links
WHERE links_public = '1'
AND (links_description LIKE '%$filter%'
OR links_created_by LIKE '%$filter%' OR links_link LIKE '%$filter%' )
ORDER BY links_created DESC