<%@ language = "vbscript" codepage = 936%>
<%
option explicit '強制定義變量
dim idcount'記錄總數
dim pages'每頁條數
dim pagec'總頁數
dim page'頁碼
dim pagenc '每頁顯示的分頁頁碼數量=pagenc*2+1
pagenc=2
dim pagenmax '每頁顯示的分頁的最大頁碼
dim pagenmin '每頁顯示的分頁的最小頁碼
page=clng(request("page"))
dim start'程序開始的時間
dim endt'程序結束的時間
dim datafrom'數據表名
datafrom="table1"
dim conn,rs
dim datapath '數據庫路經
dim sqlid'本頁需要用到的id
dim myself'本頁地址
myself = request.servervariables("path_info")
dim sql'sql語句
dim taxis'排序的語句
'taxis="order by id asc" '正排序
taxis="order by id desc" '倒排序
dim i'用於循環的整數
start=timer()
datapath="db.mdb"'數據庫
pages=30
'連接打開數據庫
dim db
db="db.mdb" '定義數據庫路徑及名稱
set conn = server.createobject("adodb.connection")
conn.open "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath(db)
if err.number <> 0 then
response.write "數據庫鏈接出錯!"
response.end()
end if
'獲取記錄總數
sql="select count(id) as idcount from ["& datafrom &"]"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,0,1
idcount=rs("idcount")'獲取記錄總數
if(idcount>0) then'如果記錄總數=0,則不處理
if(idcount mod pages=0)then'如果記錄總數除以每頁條數有余數,則=記錄總數/每頁條數+1
pagec=int(idcount/pages)'獲取總頁數
else
pagec=int(idcount/pages)+1'獲取總頁數
end if
'獲取本頁需要用到的id============================================
'讀取所有記錄的id數值,因為只有id所以速度很快
sql="select id from ["& datafrom &"] " & taxis
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,1,1
rs.pagesize = pages '每頁顯示記錄數
if page < 1 then page = 1
if page > pagec then page = pagec
if pagec > 0 then rs.absolutepage = page
for i=1 to rs.pagesize
if rs.eof then exit for
if(i=1)then
sqlid=rs("id")
else
sqlid=sqlid &","&rs("id")
end if
rs.movenext
next
'獲取本頁需要用到的id結束============================================
end if
%>
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<title>快速分頁</title>
<link rel="stylesheet" href="page.css" type="text/css">
</head>
<body bgcolor="#f2f2f2" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="100%" height="100%" border="0" cellpadding="20" cellspacing="0">