日期:2010-08-25  浏览次数:21082 次

<%@ 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">
  <tr>
    <td valign="middle"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
      <tr>
        <td valign="top" bgcolor="#ffffff"><br>          <table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="zw">
          <tr>
            <td><strong><font color="#ff6600">快速分页</font></strong></td>
          </tr>
        </table>
          <br>
          <table width="90%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="cccccc" class="zw">
            <tr