Php 多重条件和身份检查
您好,我有一个mysql查询,需要检查多个条件,因此我使用()来分隔每个条件,例如:Php 多重条件和身份检查,php,mysql,where,conditional-statements,Php,Mysql,Where,Conditional Statements,您好,我有一个mysql查询,需要检查多个条件,因此我使用()来分隔每个条件,例如: WHERE (a='string' AND b='string') OR (a='otherstring' AND b='otherstring) // Condition 1 ( this=somethingelse and this2=somethingelse2 ) // Condition 2 and ( someCondition=anotherConidition
WHERE (a='string' AND b='string') OR (a='otherstring' AND b='otherstring)
// Condition 1
(
this=somethingelse
and this2=somethingelse2
)
// Condition 2
and
(
someCondition=anotherConidition
and
// Condition 3
(
thirdCondition=anotherCondition3
or thirdCondition2=anotherCondition4
)
)
我的问题是,我必须添加一个用户检查,例如,我不知道是否必须再次使用(),这是否正确
WHERE ((a='string' AND b='string') OR (a='otherstring' AND b='otherstring)) AND (id='1')
谢谢 这可能与您的代码有关,您在上一个条件中没有关闭字符串。请尝试此操作
在哪里
(
(a='string'和b='string')或(a='otherstring'和b='otherstring')
)
和(id='1')
这将查找id为1且其中a.string=b.string或a.string=otherstring的所有记录
编辑:仅为进一步澄清:
基本上,括号内的任何内容都等同于一起,例如:
WHERE (a='string' AND b='string') OR (a='otherstring' AND b='otherstring)
// Condition 1
(
this=somethingelse
and this2=somethingelse2
)
// Condition 2
and
(
someCondition=anotherConidition
and
// Condition 3
(
thirdCondition=anotherCondition3
or thirdCondition2=anotherCondition4
)
)
在这个例子中。必须满足条件1中的两个条款。条件2也必须满足,在该条件中,
someCondition必须等于另一个条件以及条件3中的任一语句。我在句子中忘记了a。是的!我的问题是关于double()来封装一个封闭条件。我理解id='1'上的()不是必需的,对吗?@Nachonavelhan如果我提供的答案回答了您的问题,请接受。是的,对不起,我正在等待最短的时间来回答。:)