日期:2008-10-19  浏览次数:21148 次

以下是search搜索代码:

Set rs = Server.CreateObject("ADODB.Recordset")


searchdata=request("T1")
if trim(searchdata)="" then
response.write "<script>alert('请输入查询搜索关键字!');history.back();</script>"
response.end
end if
searchdata=replace(searchdata,"'","’")
searchdata=Rtrim(LTrim(searchdata))
sql1=""
sql2=""
sql3=""
searchdatatmp=split(searchdata," ")
max=ubound(searchdatatmp)
if max=0 then '如果max等于0说明只输入了一个关键字,那么就不需要循环处理
sql1=sql1&" key like '%" & searchdatatmp(i) & "%' " '网站关键字模糊搜索
sql2=sql2&" sitename like '%" & searchdatatmp(i) & "%' " '网站标题模糊搜索
sql3=sql3&" faq like '%" & searchdatatmp(i) & "%' " '网站简要说明搜索
else '如果含有多个关键字,采用循环处理sql语句
for i=0 to max '如果关键字很多,我们要求每一个搜索都要匹配每一个关键字,通过循环来实现
if trim(searchdatatmp(i))<>"" then
'=============================================================================
sqltmp="select * from key where keyname like '%"&ArraySearchdata(i)&"%'"
rs.open sqltmp,conn,1,3
if rs.eof and rs.bof then
rs.addnew
rs("keyname")=ArraySearchdata(i)
else
rs("keyhot")=rs("keyhot")+1
end if
rs.update
rs.close
'=============================================================================
end if
if i=0 then '写入下面sql语句作为开头,仔细研究一下下面的代码
sql1=sql1&" (key like '%" & searchdatatmp(i) & "%' and "
sql2=sql2&" (sitename like '%" & searchdatatmp(i) & "%' and "
sql3=sql3&" (faq like '%" & searchdatatmp(i) & "%' and "
else
if i=max then '如果循环到最后一个关键字,写入下面sql语句作为结尾
sql1=sql1&" key like '%" & searchdatatmp(i) & "%') "
sql2=sql2&" sitename like '%" & searchdatatmp(i) & "%') "
sql3=sql3&" faq like '%" & searchdatatmp(i) & "%') "
else '如果关键自己不是开头的也不是结尾的,那么循坏写入下面的sql语句
sql1=sql1&" key like '%" & searchdatatmp(i) & "%' and "
sql2=sql2&" sitename like '%" & searchdatatmp(i) & "%' and "
sql3=sql3&" faq like '%" & searchdatatmp(i) & "%' and "
end if
end if
next '循环结束
end if
sql="select * from www where "&sql1&" or "&sql2&" or "&sql3"&"order by level desc,hot desc"
rs.Open sql,conn, 1, 1
if not rs.eof then
If Request.querystring("CurPage") = "" or Request.querystring("CurPage") = 0 then
CurPage = 1
Else
CurPage = CINT(Request("CurPage"))
End If

rs.PageSize=20
Dim TotalPages
TotalPages = rs.PageCount
If CurPage>rs.Pagecount Then
CurPage=rs.Pagecount
end if
rs.AbsolutePage=CurPage
rs.CacheSize = rs.PageSize
Dim Totalcount
Totalcount =INT(rs.recordcount)
order=0
do while (not rs.eof) and (order<rs.PageSize)
order=order+1
%><font color="#FF0000">○</font><a href="goturl.ASP?id=<%=rs("id")%>&url=<%=rs("url")%>" target="_blank"><font color="#0000FF"><%
for j=0 to i
if j=0 then
sitenameTmp=replace(rs("sitename"),ArraySearchdata(j),"<font color=red>"&ArraySearchdata(j)&"</font>")
else
sitenameTmp=replace(sitenameTmp,ArraySearchdata(j),"<font color=red>"&ArraySearchdata(j)&"</font>")
end if
next
response.write sitenameTmp%></font></a>
---<%for j=0 to i
if j=0 then
sitenameTmp=replace(rs("faq"),ArraySearchdata(j),"<font color=red>"&ArraySearchdata(j)&"</font>")
else
sitenameTmp=replace(sitenameTmp,ArraySearchdata(j),"<font color=red>"&ArraySearchdata(j)&"</font>")
end if
next
response.write sitenameTmp%>
<%
rs.movenext
loop
%> <table>
<tr> <td width="30%">○页次: <%=CurPage%> / <%=TotalPages%></td>
<td width="20%"></td>