
展开全部
第一段代码:可以复制粘贴到任何一个HTM代码的<body></body>中间
<form name="search" action="search.asp" method="post" class="top_search">
<span class="search"><img src="Images/index_r4_c24.jpg" /></span>
<input id="keywords" name="keywords" type="text" value="" />
<input type="submit" name="submit" value="" id="submit" />
</form>
第二段代码,放在 search.asp中<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>下面:
<!--#include file="Connections/conn_web.asp" -->
<!--#include file="inc/inc_function.asp"-->
<%
keywords = Trim(Request.Form("keywords"))
IF keywords <> "" Then
SQLString = "Select * From table_infomation Where info_title like '%" & keywords & "%' or info_content like '%" & keywords & "%' Order by info_Createdate DESC"
pagecondition = " info_title like '%" & keywords & "%' or info_content like '%" & keywords & "%' "
Else
SQLString = "Select * From table_infomation Order by info_Createdate DESC"
pagecondition = ""
End IF
第三段代码,放在search.asp中<body></body>中间,完成查询结果输出。
<div class="rightside">
<%
TotalRow=Recordcounts("table_infomation",pagecondition,"info_ID") '调用函数Recordcounts来取出记录总数
IF TotalRow < 1 Then
Resault = "没有搜索到任何可用信息,您可以返回重试或者浏览本站其它信息。"
Else
Resault = "搜索到可用信息" & TotalRow & "条:"
End IF
%>
<div style="width:700px; height:30px; border:solid 1px #0099FF; font-family:'宋体'; font-size:14px; color:#0000FF; padding:10px;"><%=Resault%></div>
<ul class="news_list">
<%
NewsRow = 1
PageSize=15
IF Request.QueryString("Page")<>"" Then
CurrentPage=Int(Request.QueryString("Page"))
Else
CurrentPage=1
End IF
TotalPage=Cint(TotalRow/PageSize)
IF TotalPage=0 Then TotalPage=1
IF TotalRow>TotalPage*PageSize Then TotalPage=TotalPage+1
Set MM_Recordset = GetRecordset(SQLString) '调用函数GetRecordset打开记录集
IF CurrentPage<>1 Then MM_Recordset.Move (CurrentPage-1)*PageSize
Do While Not MM_Recordset.Eof
Info_intro = InterceptString(MM_Recordset.Fields.Item("Info_title").Value,300)
Set Article_sorts_rs = GetRecordset("Select Ca_name From table_category Where Ca_order = '" & MM_Recordset.Fields.Item("Info_cateID").Value & "'")
Article_sorts = Article_sorts_rs.Fields.Item("Ca_name").Value
ReleaseRecordset(Article_sorts_rs)
%>
<li>[<a href="news_list.asp?CID=<%=MM_Recordset.Fields.Item("Info_cateID").Value%>" style="color:#0066CC;"><%=Article_sorts%></a>]<a href="news_disp.asp?AID=<%=MM_Recordset.Fields.Item("Info_ID").Value%>"><%=Info_intro%></a><span style="float:right; width:100px;"><%=MM_Recordset.Fields.Item("Info_createdate").Value%></span></li>
<%
NewsRow = NewsRow + 1
MM_Recordset.Movenext
IF NewsRow > pagesize Then Exit Do
Loop
ReleaseRecordset(MM_Recordset) '调用函数ReleaseRecordset关闭记录集并释放变量MM_Recordset
%>
</ul>
<div class="page_info"> 共<%=TotalRow%>条,每页显示<%=PageSize%>条
<%IF CurrentPage<>1 Then%>
<a href="?cateID=<%=cateid%>&page=1">第一页</a> <a href="?cateID=<%=cateid%>&page=<%=CurrentPage-1%>">上一页</a>
<%End IF
for i=(CurrentPage-2) to (CurrentPage+2)
IF i>0 and i<=totalPage Then
IF i=CurrentPage Then
Response.Write("<font color=""#FF0000""> "&i&" </Font>")
Else
Response.Write(" <a href=""?cateID="&cateid&"&page="&i&""">"&i&"</a> ")
End if
End IF
Next
IF CurrentPage<>TotalPage and CurrentPage<>0 Then%>
<a href="?cateID=<%=cateid%>&page=<%=CurrentPage+1%>">下一页</a> <a href="?cateID=<%=cateid%>&page=<%=TotalPage%>">最后一页</a>
<%End IF%>
<%=CurrentPage%>/<%=TotalPage%></div>
</div>
用到的函数:
Function GetRecordset(SQLString)
Dim MM_Recordset_cmd
Set MM_Recordset_cmd = Server.CreateObject ("ADODB.Command")
MM_Recordset_cmd.ActiveConnection = MM_Conn_STRING
MM_Recordset_cmd.CommandText = SQLString
MM_Recordset_cmd.Prepared = true
Set GetRecordset = MM_Recordset_cmd.Execute
End Function
Sub ReleaseRecordset(MM_Recordset)
MM_Recordset.Close
Set MM_Recordset = Nothing
End Sub
Function Recordcounts(tablename,constr,Indexfieldname)
Dim tempsql,tempRecordset
IF constr = "" Then
tempsql = "Select count(" & Indexfieldname &") As IDCount From " & tablename & ""
Else
tempsql = "Select count(" & Indexfieldname &") As IDCount From " & tablename & " Where " & constr
End IF
Set tempRecordset = GetRecordset(tempsql)
Recordcounts = tempRecordset.Fields.Item("IDCount").Value
ReleaseRecordset(tempRecordset)
Set tempRecordset = Nothing
Set tempsql = Nothing
End Function
先解释一下,这是我给客户的网站上做的信息查询(在任何页面上都有一个查询框,点输入关键字之后点查询直接都会提交到search.asp这个文件。
<form name="search" action="search.asp" method="post" class="top_search">
<span class="search"><img src="Images/index_r4_c24.jpg" /></span>
<input id="keywords" name="keywords" type="text" value="" />
<input type="submit" name="submit" value="" id="submit" />
</form>
第二段代码,放在 search.asp中<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>下面:
<!--#include file="Connections/conn_web.asp" -->
<!--#include file="inc/inc_function.asp"-->
<%
keywords = Trim(Request.Form("keywords"))
IF keywords <> "" Then
SQLString = "Select * From table_infomation Where info_title like '%" & keywords & "%' or info_content like '%" & keywords & "%' Order by info_Createdate DESC"
pagecondition = " info_title like '%" & keywords & "%' or info_content like '%" & keywords & "%' "
Else
SQLString = "Select * From table_infomation Order by info_Createdate DESC"
pagecondition = ""
End IF
第三段代码,放在search.asp中<body></body>中间,完成查询结果输出。
<div class="rightside">
<%
TotalRow=Recordcounts("table_infomation",pagecondition,"info_ID") '调用函数Recordcounts来取出记录总数
IF TotalRow < 1 Then
Resault = "没有搜索到任何可用信息,您可以返回重试或者浏览本站其它信息。"
Else
Resault = "搜索到可用信息" & TotalRow & "条:"
End IF
%>
<div style="width:700px; height:30px; border:solid 1px #0099FF; font-family:'宋体'; font-size:14px; color:#0000FF; padding:10px;"><%=Resault%></div>
<ul class="news_list">
<%
NewsRow = 1
PageSize=15
IF Request.QueryString("Page")<>"" Then
CurrentPage=Int(Request.QueryString("Page"))
Else
CurrentPage=1
End IF
TotalPage=Cint(TotalRow/PageSize)
IF TotalPage=0 Then TotalPage=1
IF TotalRow>TotalPage*PageSize Then TotalPage=TotalPage+1
Set MM_Recordset = GetRecordset(SQLString) '调用函数GetRecordset打开记录集
IF CurrentPage<>1 Then MM_Recordset.Move (CurrentPage-1)*PageSize
Do While Not MM_Recordset.Eof
Info_intro = InterceptString(MM_Recordset.Fields.Item("Info_title").Value,300)
Set Article_sorts_rs = GetRecordset("Select Ca_name From table_category Where Ca_order = '" & MM_Recordset.Fields.Item("Info_cateID").Value & "'")
Article_sorts = Article_sorts_rs.Fields.Item("Ca_name").Value
ReleaseRecordset(Article_sorts_rs)
%>
<li>[<a href="news_list.asp?CID=<%=MM_Recordset.Fields.Item("Info_cateID").Value%>" style="color:#0066CC;"><%=Article_sorts%></a>]<a href="news_disp.asp?AID=<%=MM_Recordset.Fields.Item("Info_ID").Value%>"><%=Info_intro%></a><span style="float:right; width:100px;"><%=MM_Recordset.Fields.Item("Info_createdate").Value%></span></li>
<%
NewsRow = NewsRow + 1
MM_Recordset.Movenext
IF NewsRow > pagesize Then Exit Do
Loop
ReleaseRecordset(MM_Recordset) '调用函数ReleaseRecordset关闭记录集并释放变量MM_Recordset
%>
</ul>
<div class="page_info"> 共<%=TotalRow%>条,每页显示<%=PageSize%>条
<%IF CurrentPage<>1 Then%>
<a href="?cateID=<%=cateid%>&page=1">第一页</a> <a href="?cateID=<%=cateid%>&page=<%=CurrentPage-1%>">上一页</a>
<%End IF
for i=(CurrentPage-2) to (CurrentPage+2)
IF i>0 and i<=totalPage Then
IF i=CurrentPage Then
Response.Write("<font color=""#FF0000""> "&i&" </Font>")
Else
Response.Write(" <a href=""?cateID="&cateid&"&page="&i&""">"&i&"</a> ")
End if
End IF
Next
IF CurrentPage<>TotalPage and CurrentPage<>0 Then%>
<a href="?cateID=<%=cateid%>&page=<%=CurrentPage+1%>">下一页</a> <a href="?cateID=<%=cateid%>&page=<%=TotalPage%>">最后一页</a>
<%End IF%>
<%=CurrentPage%>/<%=TotalPage%></div>
</div>
用到的函数:
Function GetRecordset(SQLString)
Dim MM_Recordset_cmd
Set MM_Recordset_cmd = Server.CreateObject ("ADODB.Command")
MM_Recordset_cmd.ActiveConnection = MM_Conn_STRING
MM_Recordset_cmd.CommandText = SQLString
MM_Recordset_cmd.Prepared = true
Set GetRecordset = MM_Recordset_cmd.Execute
End Function
Sub ReleaseRecordset(MM_Recordset)
MM_Recordset.Close
Set MM_Recordset = Nothing
End Sub
Function Recordcounts(tablename,constr,Indexfieldname)
Dim tempsql,tempRecordset
IF constr = "" Then
tempsql = "Select count(" & Indexfieldname &") As IDCount From " & tablename & ""
Else
tempsql = "Select count(" & Indexfieldname &") As IDCount From " & tablename & " Where " & constr
End IF
Set tempRecordset = GetRecordset(tempsql)
Recordcounts = tempRecordset.Fields.Item("IDCount").Value
ReleaseRecordset(tempRecordset)
Set tempRecordset = Nothing
Set tempsql = Nothing
End Function
先解释一下,这是我给客户的网站上做的信息查询(在任何页面上都有一个查询框,点输入关键字之后点查询直接都会提交到search.asp这个文件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询