给段代码你参考下,非常适合做 多条件 搜索
<%
tj=request("tj")
categoryid=request("categoryid")
id=request("id")
key=request("key")
pid=request("pid")
bigclassid=request("bigclassid")
smallclassid=request("smallclassid")
selectm=request("selectm")
set rspp=Server.CreateObject("ADODB.RecordSet")
sqln="SELECT * FROM product WHERE recommend <>3 AND"
If pid<>"" Then
sqln=sqln&" mark="&pid&" AND"
end if
If tj<>"" Then
sqln=sqln&" recommend=2 AND"
end if
'搜索类型
if key<>"" and selectm=1 then
sqln=sqln&" name like '%"&key&"%'AND"
end if
if key<>"" and selectm=2 then
sqln=sqln&" introduce like '%"&key&"%'AND"
end if
if key<>"" and selectm=3 then
sqln=sqln&" code like '%"&key&"%'AND"
end if
if categoryid="no"then
categoryid=""
end if
if categoryid<>"" then
sqln=sqln&" categoryid="&categoryid&" AND"
end if
if smallclassid<>"" then
sqln=sqln&" smallclassid="&smallclassid&" AND"
end if
if id<>""then
sqln=sqln&" id="&id&" AND"
end if
if bigclassid<>""then
sqln=sqln&" bigclassid="&bigclassid&" AND"
end if
'
if right(sqln,5)="WHERE" then
sqln=left(sqln,clng(len(sqln))-5) '解决所有参数都为空的情况
end if
if right(sqln,3)="AND" then
sqln=left(sqln,clng(len(sqln))-3) '
end if
sqln=sqln&" ORDER BY adddate "
rspp.open sqln,conn,1,1
%>