PHP多条件模糊查询如何写(原先是asp的想写成php)
ifrequest("ckc")="查"thenifrequest("bh")<>""thenifcond=""thencond="编号like'%"&trim(requ...
if request("ckc")="查" then
if request("bh")<>""then
if cond="" then
cond="编号 like '%" & trim(request("bh")) & "%'"
else
cond = cond & " AND 编号 like '%" & trim(request("bh")) & "%'"
end if
end if
if request("ckbh")<>""then
if cond="" then
cond="出库编号 like '%" & trim(request("ckbh")) & "%'"
else
cond = cond & " AND 出库编号 like '%" & trim(request("ckbh")) & "%'"
end if
end if
if request("clmc")<>"" then
If cond="" Then
cond="材料名称 like '%" & trim(request("clmc")) & "%'"
else
cond = cond & "and 材料名称 like '%" & trim(request("clmc")) & "%'"
end if
end if
if request("ksrq")<>"" then
if cond="" then
cond="日期>=# " & trim(request("ksrq")) & "#"
else
cond=cond & "and 日期>=# " & trim(request("ksrq")) & "#"
end if
end if
if request("jsrq")<>"" then
if cond="" then
cond="日期<=# " & trim(request("jsrq")) & "#"
else
cond=cond &"and 日期<=# " & trim(request("jsrq")) & "#"
end if
end if
if request("dcdw")<>""then
if cond="" then
cond="调出单位 like '%" & trim(request("dcdw")) & "%'"
else
cond = cond & " AND 调出单位 like '%" & trim(request("dcdw")) & "%'"
end if
end if
if request("drdw")<>""then
if cond="" then
cond="调入单位 like '%" & trim(request("drdw")) & "%'"
else
cond = cond & " AND 调入单位 like '%" & trim(request("drdw")) & "%'"
end if
end if
if cond<>""then
sql="select * from 出库表 where " & cond & "order by 日期"
else
sql="select * from 出库表 order by 日期"
end if
session("sql")=(sql)
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1 展开
if request("bh")<>""then
if cond="" then
cond="编号 like '%" & trim(request("bh")) & "%'"
else
cond = cond & " AND 编号 like '%" & trim(request("bh")) & "%'"
end if
end if
if request("ckbh")<>""then
if cond="" then
cond="出库编号 like '%" & trim(request("ckbh")) & "%'"
else
cond = cond & " AND 出库编号 like '%" & trim(request("ckbh")) & "%'"
end if
end if
if request("clmc")<>"" then
If cond="" Then
cond="材料名称 like '%" & trim(request("clmc")) & "%'"
else
cond = cond & "and 材料名称 like '%" & trim(request("clmc")) & "%'"
end if
end if
if request("ksrq")<>"" then
if cond="" then
cond="日期>=# " & trim(request("ksrq")) & "#"
else
cond=cond & "and 日期>=# " & trim(request("ksrq")) & "#"
end if
end if
if request("jsrq")<>"" then
if cond="" then
cond="日期<=# " & trim(request("jsrq")) & "#"
else
cond=cond &"and 日期<=# " & trim(request("jsrq")) & "#"
end if
end if
if request("dcdw")<>""then
if cond="" then
cond="调出单位 like '%" & trim(request("dcdw")) & "%'"
else
cond = cond & " AND 调出单位 like '%" & trim(request("dcdw")) & "%'"
end if
end if
if request("drdw")<>""then
if cond="" then
cond="调入单位 like '%" & trim(request("drdw")) & "%'"
else
cond = cond & " AND 调入单位 like '%" & trim(request("drdw")) & "%'"
end if
end if
if cond<>""then
sql="select * from 出库表 where " & cond & "order by 日期"
else
sql="select * from 出库表 order by 日期"
end if
session("sql")=(sql)
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1 展开
展开全部
完全一样的写法呀,只是变量前面加个$、then用{}代替等,例如前几行代码这样:
$cond='';
if ($_POST["ckc"]=="查"){
if ($_POST["bh"]!="") {
if ($cond=="") $cond="编号 like '%" & trim(request("bh")) & "%'";
else $cond = cond . " AND 编号 like '%" & trim(request("bh")) & "%'";
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询