如下所示,请问这段代码该怎么改?才能实现我的要求呢?

<!--#include file="conn.asp" -->
<%
if request.querystring("act")="cha" Then
exec="select * from juanban where 材质 like '"&request.form("caizhi")&"' or 规格 like '"&request.form("guige")&"' or 产地 like '"&request.form("chandi")&"' or 货源 like '"&request.form("huoyuan")&"'"
else
exec="select * from juanban where 1=1"
end if
set rs2=server.createobject("adodb.recordset")
rs2.open exec,conn,1,1
do while not rs2.eof %>
如图
要求某个条件为空时不影响其他的,可以单条件搜索,也可以多条件搜索,上面这段代码怎么改?

http://img2.mukewang.com/6253d8c40001189905930132.jpg

拉风的咖菲猫
浏览 157回答 3
3回答

胡子哥哥

asp多条件符合查询,参考代码如下:<%dim qyqy=0if request.form("stu_name")<>"" then '第一个条件表单传递的数据str="stu_name='"&request.form("stu_name")&"'"qy=qy+1end ifif request.form("stu_num")<>"" then '第二个条件表单传递的数据if qy=0 thenstr=str&"stu_number='"&request.form("stu_num")&"'"elsestr=str&"and stu_number='"&request.form("stu_num")&"'"end ifqy=qy+1end ifif request.form("stu_xibie")<>"" then '第三个条件表单传递的数据if qy=0 thenstr=str&"stu_xibie='"&request.form("stu_xibie")&"'"elsestr=str&"and stu_xibie='"&request.form("stu_xibie")&"'"end ifqy=qy+1end ifif request.form("stu_class")<>"" thenif qy=0 thenstr=str&"stu_class='"&request.form("stu_class")&"'"elsestr=str&"and stu_class='"&request.form("stu_class")&"'"end ifqy=qy+1end ifif request.form("stu_year")<>"" thenif qy=0 thenstr=str&"stu_year='"&request.form("stu_year")&"'"elsestr=str&"and stu_year='"&request.form("stu_year")&"'"end ifqy=qy+1end ifsql="select * from [students] where "&strSet rs=Conn.Execute(sql) '执行sql语句%>

慕勒3428872

代码我就不写啦,给你思路,自己想出来的会一直记得,别人代码看一遍过几天就会忘记。首先接收request传递参数,分开接收,在判断接收的后赋值的变量是否为空,例如:接收a=request.form(“a”)b=request.form(“b”)判断if a=“”and b<>"" then执行条件查询(这里只需要查询a)以此类推

慕斯王

<%if request.querystring("act")="cha" Thencaizhi=request("caizhi")guige=request("guige")chandi=request("chandi")huoyuan=request("huoyuan")if caizhi="" and guige="" and chandi="" and huoyuan="" thenexec="select * from juanban where 1=1"elseexec="select * from juanban where 材质 like '"&caizhi&"' or 规格 like '"&guige&"' or 产地 like '"&chandi&"' or 货源 like '"&huoyuan&"'"end ifend ifset rs2=server.createobject("adodb.recordset")rs2.open exec,conn,1,1do while not rs2.eof %>
打开App,查看更多内容
随时随地看视频慕课网APP