-----------------------下面保存為search.asp--------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件</title>
</head>
<body bgcolor="#ffffff">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<script>
function btn_ck_bh_Click()
{
var cx = document.form1.cxsj.value;
form1.action ="search.asp?cx="+cx;
}
</script>
<table border="1" cellspacing="0" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" width="88%" style="word-break:break-all">
<tr>
<td width="778" align="center" colspan="7">
<form method="POST" name="form1" action=search.asp>
<p>輸入搜索內容:<input type="text" name="cxsj" size="20"><input type="submit" value="提交" name="B1" LANGUAGE="javascript" onclick="btn_ck_bh_Click()">
<input type="reset" value="重寫" name="B2"></p>
</form>
</td>
</tr>
</table>
<table border="1" cellspacing="0" bgcolor="#F0F8FF" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" width="88%" style="word-break:break-all">
<tr>
<td width="8%" align="center"><strong><font color="#0080C0">ID 號</font></strong></td>
<td width="58%" align="center"><strong><font color="#0080C0">標 題</font></strong></td>
<td width="8%" align="center"><strong><font color="#0080C0">修 改</font></strong></td>
<td width="8%" align="center"><strong><font color="#0080C0">刪 除</font></strong></td>
</tr>
<%
'數據庫查詢
'獲得搜索內容
cx = request("cx")
dim pageCount
'把page轉換成整數
page = cint(request("page"))
set conn=server.createobject("adodb.connection")'
set rs=server.createobject("adodb.recordset")
conn.open "DBQ=" & server.mappath("./news.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
' 獲取產品的名字記錄集(從 news表中)
if cx <> "" then
sql = "select * from news where title like '%"&cx& "%' order by id desc"
else
sql ="select * from news order by id desc"
end if
rs.open sql,conn,3,3
'如果沒有數據記錄
if rs.bof then
errmsg=errmsg+"<br>"+"<li>"+keyword+"沒有記錄,請返回!!"
response.write errmsg
response.end
end if
' 設置記錄集在每頁的總行數,也就是 PageSize屬性
RS.PageSize=40
'把rs.pageCount轉換成整數和page才能作比較
pageCount = cint(rs.pageCount)
' 設置當前的頁號( AbsolutePage屬性)
if page = 0 then
page =1
end if
RS.AbsolutePage = page
x=1
' 顯示當前頁中的所有記錄( PageSize中設置的行數)
WHILE NOT RS.EOF AND NumRows<RS.PageSize
%>
<tr onmouseover="this.bgColor='#99ccff'" onmouseout="this.bgColor=''">
<td width="8%"><p align="center"><%=rs("id")%></td>
<td width="58%"><a href="view.asp?id=<%=rs("id")%>" target="_blank"><%=rs("title")%></a></td>
<td width="8%" align="center"><a href="edit.asp?id="<%=rs("id")%>>修 改</a></td>
<td width="8%" align="center"><a href="delet.asp?id="<%=rs("id")%>>刪 除</a></td>
</tr>
<%RS.MoveNext
NumRows=NumRows+1
WEND%>
<tr onmouseover="this.bgColor='#99ccff'" onmouseout="this.bgColor=''">
<td width="105%" align="center" colspan="6"> </td> </tr>
<tr>
<td width="105%" align="center" colspan="6">
<p align="center"><FONT color=#333333>***<%=PageCount%>頁 第<%=page%>頁★
<%if page=1 then%>首頁<%end if%>
<%if page>1 then%>
<A HREF="search.asp?page=1&cx=<%=cx%>"> 首頁</A>
<%end if%>★
<%if page>1 then%><A HREF="search.asp?page=<%=page-1%>&cx=<%=cx%>"><%end if%>上壹頁</a>
<%
dim pagewhere
dim p
p = 1
'把pagewhere轉換成整數
'pagewhere = cint(request("pagewhere"))
pagewhere = pageCount
if pagewhere>0 then
for p=1 to pagewhere
if p <> page then%>
<A HREF="search.asp?page=<%=p%>&cx=<%=cx%>"><%=p%></a>
<%end if
if p =page then%>
<%=p%>
<% end if
next
end if%>
<%if page < PageCount then%>
<A HREF="search.asp?page=<%=page+1%>&cx=<%=cx%>">
<%end if %>下壹頁</A>★
<%if page=PageCount then%>尾頁
<%end if%>
<%if page<PageCount then%>
<A HREF="search.asp?page=<%=PageCount%>&cx=<%=cx%>"> 尾頁</A>
<%end if%>
</p></FONT></td> </tr> <tr>
<td width="105%" align="center" colspan="6">搜索內容:<%=cx%></td>
</tr>
</table></center></div>
</body></html>
<%
rs.close
Set rs=nothing
conn.close
set conn=nothing
%>