利用ASP实现数据库的模糊查询,请指出哪些是主要代码并解释含义
系统根据用户输入的查询信息,利用%进行字符串的匹配,用LIKE对形成的字符串进行比较,在数据库中查询出与用户输入相关的产品的信息,并将信息反馈给用户。主要实现代码如下:sql2="searchkey="&searchkey&"&anclassid="&anclassid&"&jiage="&jiage&"&action="&action&"&selectname="&selectname
if anclassid<>0 then '//判断查询分类,分类不为空。
select case action
case "1"
sql1=" shopname like '%"&searchkey&"%' and (shichangjia<"&jiage&" or huiyuanjia<"&jiage&" or vipjia<"&jiage&") and anclassid="&anclassid&" "
case "2"
sql1=" pingpai like '%"&selectname&"%' and (shichangjia<"&jiage&" or huiyuanjia<"&jiage&" or vipjia<"&jiage&") and anclassid="&anclassid&" "
case "3"
sql1=" shopcontent like '%"&searchkey&"%' and (shichangjia<"&jiage&" or huiyuanjia<"&jiage&" or vipjia<"&jiage&") and anclassid="&anclassid&" "
end select
else
'//分类为空//
select case action
case "1"
sql1=" shopname like '%"&searchkey&"%' and (shichangjia<"&jiage&" or huiyuanjia<"&jiage&" or vipjia<"&jiage&") "
case "2"
sql1=" pingpai like '%"&selectname&"%' and (shichangjia<"&jiage&" or huiyuanjia<"&jiage&" or vipjia<"&jiage&") "
case "3"
sql1=" shopcontent like '%"&searchkey&"%' and (shichangjia<"&jiage&" or huiyuanjia<"&jiage&" or vipjia<"&jiage&") "
end select
end if
end if
call sss()
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from shop_snsn where "&sql1&" order by adddate desc",conn,1,1
if rs.eof And rs.bof then
Response.Write "<p align='center' > 对不起,没有查询到您需要的商品!</p>"
else
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,"research.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim shopmark
shopmark=rs.shopmark
showContent
showpage totalput,MaxPerPage,"research.asp"
else
currentPage=1
showContent
showpage totalput,MaxPerPage,"research.asp"
end if
end if
end if