pro*_*yb3 1 php mysql operators operator-precedence
假设我使用2 AND和1 OR来检索结果,首先使用输入文本值进行测试name,我可以得到正确的结果但是当我更改$getc为除空字符串以外的任何值时,结果不会更改,它只查询name值.怎么了?
$query1 = "SELECT * FROM $tableName WHERE name LIKE '%$asd%' OR descriptions LIKE
'%$asd%' AND category='$getc' AND company_type='$dsp' LIMIT $start, $limit";
Run Code Online (Sandbox Code Playgroud)
尝试()四处走动name LIKE '%$asd%' OR descriptions LIKE '%$asd%':
$query1 = "SELECT * FROM $tableName WHERE (name LIKE '%$asd%' OR descriptions LIKE '%$asd%') AND category='$getc' AND company_type='$dsp' LIMIT $start, $limit";
Run Code Online (Sandbox Code Playgroud)
它说category,并company_type 必须匹配,并且至少一个的name和descriptions必须匹配.
原因:
a OR b AND c AND d
Run Code Online (Sandbox Code Playgroud)
被视为以下作为AND由具有更高的优先级比OR
a OR (b AND c AND d)
Run Code Online (Sandbox Code Playgroud)
但你想要的是:
(a OR b) AND c AND d
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
75 次 |
| 最近记录: |