分页列表需要配合我的JS分页列表使用,连接参数为:
'----------参数---------------
DATAPATH = "test.mdb" ' 数据库路径
Table_Name = "test2" '表名
Table_Fields = "id,username,title,tim" '字段集合
Table_Id = "id" '主ID
Table_Condition = ""
Table_Order = "order by id desc" '排序
PageSize = 20 '每页记录条数
Const Update = True '是否立即更新
下面是代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
Option Explicit
Dim BeginTime,EndTime:BeginTime=Timer
'---------open data source------
Function OpenConn(dbPath)
On Error Resume Next
Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source="&Server.MapPath(dbPath)
Conn.Open
CheckErr Err.Number=0,"找不到数据库"
Set OpenConn = Conn
End Function
Sub CheckErr(expression,events)
If expression=False Then
'Response.Clear
Response.Write "<style>body{font-size:11pt;}</style><body leftmargin=0 topmargin=0 marginheight=0 marginwidth=0><script>document.body.innerHTML=""[<b><font color=red>Err: </font></b> ·"&events&"] <input type=button style='height:22px;width:24px;color:#319AFF;font-family: Wingdings;font-size:13pt;' value='ï' onclick='javascript:window.history.back();'>""</script>"
Response.Flush
Response.End
End If
End Sub
'--------debug--------------
Sub Debug(Name, Input)
Response.Write "<BR>"&Name&"=["&Input&"]"&"<br>"
'Response.End
End Sub
Dim Conn
Dim Rs, Sql
Dim Page
Dim PageSize
Dim PageCount
Dim RecordCount
Dim arrRS
Dim i
Dim Order
Dim DATAPATH
Dim Table_Name
Dim Table_Fields
Dim Table_Id
Dim Table_Order
Dim Table_Condition
'----------参数---------------
DATAPATH = "test.mdb" ' 数据库路径
Table_Name = "test2" '表名
Table_Fields = "id,username,title,tim" '字段集合
Table_Id = "id" '主ID
Table_Condition = ""
Table_Order = "order by id desc" '排序
PageSize = 20 '每页记录条数
Const Update = True '是否立即更新
Set Conn = OpenConn(DATAPATH)
RecordCount = Request.Cookies("JustPaging")("RecordCount")
If RecordCount = "" or Update = True Then
Sql = "Select Count("&Table_Id&") from "&Table_Name & " " & Table_Condition
RecordCount = Conn.Execute(Sql)(0) '获取记录总数
Response.Cookies("JustPaging")("RecordCount") = RecordCount
Response.Cookies("JustPaging").Expires = DateAdd("n",5,Now)
End If
RecordCount = Clng(RecordCount)
PageCount = RecordCount / PageSize '获取总页数
If RecordCount Mod PageSize <> 0 Then PageCount = PageCount + 1
Page = Request("page") '获取当前页数
If not IsNumeric(Page) Then Page = 1
Page = Clng(Page)
If Page < 1 Then Page = 1
If Page > PageCount Then Page = PageCount
Sql="Select "&Table_Fields&" from ["&Table_Name&"] " & Table_Condition & " " & Table_Order
'Set Rs = Conn.Execute(Sql)
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.Open Sql,Conn,1,1,&h0001
If not Rs.Bof And not Rs.Eof Then
Rs.Move (Page-1)*PageSize
If not Rs.Bof And not Rs.Eof Then arrRS = Rs.GetRows(PageSize) '获取记录集
End If
%>
<html>
<head>
<title>我的极速分页</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
a{font-size:9pt; color:#000000; text-decoration:none}
a:hover{COLOR:#FF3300; TEXT-DECORATION:underline}
table.list{text-decoration: none;font-size: 9pt}
tr{background-color:expression((this.sectionRowIndex%2==0)?"#e7e7e7":"#F7F7F7")}
</style>
</head>
<body>
<center>
<table border=0 cellpadding=4 class=list>
<tr><th width=5>ID</th><th width=350>POSTER</th> <th width=150>TITLE</th> <th width=140>POST TIME</th> <th>CTRL</th></tr>
<%
If IsArray(arrRS) Then
Dim id
For i = 0 To Ubound(arrRS,2)
id = arrRS(0,i)
Response.write "<tr><td> "&id&" </td><td><a href='?action=view&id="&id&"'>"&arrRS(1,i)&"</a></td> <td align=center>"&arrRS(2,i)&"</td> <td>"&arrRS(3,i)&"</td><td><a href='?action=edit&id="&id&"' title='edit'><font face=Wingdings>þ</font></a>|<a href='#' title='dele'><font face=Wingdings>ý</font></a></td></tr>"&vbCrlf
Next
Else
Response.Write "<tr><td colspan=5 align=center>无任何记录</td></tr>"
End If
%>
<tr><td colspan=5></td></tr>
<script Language="JScript" src="ShowPage.js"></script>
<tr><td colspan=2>Page: <font color=#FF3300><%=Page%></font>/<%=PageCount%> | PageSize: <%=PageSize%> | Total: <%=RecordCount%></td><td colspan=3 align=right><script>ShowPage(<%=Page%>,<%=PageCount%>,"");</script></td></tr>
<tr><td colspan=5></td></tr>
</table>
<table border=0 cellpadding=4 class=list width=30%>
<tr><td colspan=5></td></tr>
<tr><td align=center>
<%
EndTime=Timer
Response.Write "© by crazysoul Process:"&FormatNumber((EndTime-BeginTime)*1000,3)&" ms"
%>
</td></tr>
<tr><td colspan=5></td></tr>
</table>
</body>
</html>
<%
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
%>