我有一个表单,允许用户输入值,并根据他们从数据库中获得结果。我有5个文本框,我的查询是这样的
$result=mysql_query("select * from sg_report where DeclarationNo='$dec' JobNo = '$job' ConsigneeName='$cnee' ClaimNo='$claim' OR Status='$t2' OR ");
如果输入任何一个值,这会给我正确的结果。
如果我将jobNo
设为'214'并且状态为'已完成',则即使状态为“已批准”且状态为“已完成”,也会显示所有行jobNo
为“214”的记录即使jobNo
为'312',但我只想获取那些jobNo
214且状态已完成的记录。
我怎样才能做到这一点?
答案 0 :(得分:0)
您需要在语句之间使用AND条件,例如:
$ result = mysql_query(" select * from sg_report,其中DeclarationNo =' $ dec' AND JobNo =' $ job' ConsigneeName =' $ cnee&#39 ; AND ClaimNo =' $ claim' OR Status =' $ t2'");
答案 1 :(得分:0)
问题在于您的SQL查询的逻辑,如果您想要检索具有特定状态的某个JobNo AND 的所有行,那么您需要以下内容:
select * from sg_report where JobNo = '$job' AND Status='$t2'
答案 2 :(得分:0)
你可能需要这个:
$result=mysql_query("select * from sg_report where (DeclarationNo='$dec' OR '$dec'='') AND (JobNo = '$job' OR '$job'='') AND (ConsigneeName='$cnee' OR '$cnee'='') AND (ClaimNo='$claim' OR '$claim'='') AND (Status='$t2' OR '$t2'='')");
答案 3 :(得分:0)
Next time, please include php in your tags because your question contains php code. Also study mysqli or PDO because mysql commands are depreciated.
Your query missed some operators. Try this one.
$result=mysql_query("SELECT * FROM sg_report WHERE DeclarationNo='$dec' AND JobNo = '$job' AND ConsigneeName='$cnee' AND ClaimNo='$claim' AND Status='$t2'");