几个ASP的分页类 第一个<%Rem ************************************************Rem ** 作者: 萧月痕(xiaoyuehen)Rem ** ASP 通用分页类Rem ** 版本: 1.2.00Rem ** 最后修改: 2005-4-18Rem ** 版权说明: 在文档完整的前提下可任意复制, 传播.Rem ** 联系作者: xiaoyuehen(at)msn.comRem ************************************************Class Cls_PageViewPrivate sbooInitStatePrivate sstrPageUrlPrivate sstrPageVarPrivate sstrSqlPrivate sstrSqlCountPrivate sintRecordCountPrivate sintPageSizePrivate sintPageNowPrivate sintPageMaxPrivate sobjConnPrivate sstrPageInfoPrivate Sub Class_InitializeCall ClearVars()End SubPrivate Sub class_terminate()Set sobjConn = nothingEnd SubPublic Sub ClearVars()sbooInitState = FalsesstrPageUrl = ""sstrPageVar = "page"sintRecordCount = 0sintPageSize = 20sintPageNow = 0sintPageMax = 0End SubPrivate Sub ClearMainVars()sstrSql = ""End SubRem ## SQL语句Public Property Let strSQL(Value)sstrSql = ValueEnd PropertyRem ## SQL语句Public Property Let strSQLCount(Value)sstrSqlCount = ValueEnd PropertyRem ## 转向地址Public Property Let strPageurl(/blog/Value)sstrPageUrl = ValueEnd PropertyRem ## 每页显示的记录条数Public Property Let intPageSize(Value)sintPageSize = toNum(Value, 20)End PropertyRem ## 数据库连接对象Public Property Let objConn(Value)Set sobjConn = ValueEnd PropertyRem ## 当前页Public Property Let intPageNow(Value)sintPageNow = toNum(Value, 1)End PropertyRem ## 设置记录总数Public Property Let intRecordCount(Value)sintRecordCount = toNum(Value, -1)If sintRecordCount < 0 Then sintRecordCount = -1End PropertyRem ## 页面参数Public Property Let strPageVar(Value)sstrPageVar = ValueEnd PropertyRem ## 获得当前页Public Property Get intPageNow()intPageNow = singPageNowEnd PropertyRem ## 分页信息Public Property Get strPageInfo()strPageInfo = sstrPageInfoEnd PropertyRem ## 取得记录集, 二维数组或字串, 在进行循环输出时必须用 IsArray() 判断Public Property Get arrRecordInfo()Call InitClass()If Not sbooInitState ThenResponse.Write("分页类初始化失败, 请检查各参数情况")Exit PropertyEnd IfDim rs, sqlsql = sstrSqlSet rs = Server.CreateObject("Adodb.RecordSet")Rem 若记录数统计语句不为空, 则取语句执行后第一个字段值作为记录数If sstrSqlCount <> "" Thenrs.Open sstrSqlCount, sobjConn, 1, 1If Not(rs.eof or rs.bof) ThensintRecordCount = rs(0)ElsesintRecordCount = 0End Ifrs.CloseEnd Ifrs.open sql, sobjConn, 1, 1Rem 若无记录统计语句且未设定记录总数, 则由记录集RecordCount属性得出.If sintRecordCount < 0 ThensintRecordCount = rs.RecordCountEnd IfIf sintRecordCount < 0 Then sintRecordCount = 0'生成分页信息Call InitPageInfo()If Not(rs.eof or rs.bof) Thenrs.PageSize = sintPageSizers.AbsolutePage = sintPageNowIf Not(rs.eof or rs.bof) ThenarrRecordInfo = rs.getrows(sintPageSize)ElsearrRecordInfo = ""End IfElsearrRecordInfo = ""End Ifrs.closeSet rs = nothingCall ClearMainVars()End PropertyRem ## 初始化分页信息Private Sub InitPageInfo()sstrPageInfo = ""Dim surlsurl = sstrPageUrlIf Instr(1, surl, "?", 1) > 0 Thensurl = surl & "&" & sstrPageVar & "="Elsesurl = surl & "?" & sstrPageVar & "="End IfIf sintPageNow <= 0 Then sintPageNow = 1If sintRecordCount mod sintPageSize = 0 ThensintPageMax = sintRecordCount \ sintPageSizeElsesintPageMax = sintRecordCount \ sintPageSize + 1End IfIf sintPageNow > sintPageMax Then sintPageNow = sintPageMaxIf sintPageNow <= 1 thensstrPageInfo = "首页 上一页"ElsesstrPageInfo = sstrPageInfo & " <a href=""" & surl & "1"">首页</a>"sstrPageInfo = sstrPageInfo & " <a href=""" & surl & (sintPageNow - 1) & """>上一页</a>"End IfIf sintPageMax - sintPageNow < 1 thensstrPageInfo = sstrPageInfo & " 下一页 末页 "ElsesstrPageInfo = sstrPageInfo & " <a href=""" & surl & (sintPageNow + 1) & """>下一页</a> "sstrPageInfo = sstrPageInfo & " <a href=""" & surl & sintPageMax & """>末页</a> "End IfsstrPageInfo = sstrPageInfo & " 页次:<strong><font color=""#990000"">" & sintPageNow & "</font> / " & sintPageMax & " </strong>"sstrPageInfo = sstrPageInfo & " 共 <strong>" & sintRecordCount & "</strong> 条记录 <strong>" & sintPageSize & "</strong> 条/页 "End SubRem ## 长整数转换Private function toNum(s, Default)s = s & ""If s <> "" And IsNumeric(s) ThentoNum = CLng(s)ElsetoNum = DefaultEnd IfEnd functionRem ## 类初始化Public Sub InitClass()sbooInitState = TrueIf Not(IsObject(sobjConn)) ThensbooInitState = Falseresponse.write("数据库连接未指定")response.End()End IfIf Trim(sstrSql) = "" ThensbooInitState = Falseresponse.write("SQL语句未指定")response.End()End IfsintPageSize = toNum(sintPageSize, 20)If (sintPageSize < 1) Or (sintPageSize > 100) ThensbooInitState = Falseresponse.write("每页记集数未设置或不符合规则(1 - 100)")response.End()End IfsintPageNow = toNum(sintPageNow, 1)sintRecordCount = -1End SubEnd Class%> 第二个<%'================================================================='名称:叶子asp分页类'Name:ShowoPage(asp class)'RCSfile:Cls_ShowoPage.asp'Revision:0.04Beta'Author:yezi(叶子)'Date:2005-01-21 17:50:10'Description:ASP分页类,支持access/mssql/mysql/pgsql/oracle'Contact:QQ:311673,MSN:ishows@msn.com,http://www.showo.com'=================================================================Class Cls_ShowoPagePrivate Showo_PageSize,Showo_CurrPagePrivate Showo_Conn,Showo_DbType,Showo_RecType,Showo_RecSql,Showo_RecTerm,Showo_CookieNamePrivate S_Order,Showo_JsUrlPrivate Showo_Sql,Showo_Field,Showo_Table,Showo_Where,Showo_OrderBy,Showo_IdPrivate Showo_RecCount,Showo_PageCount,ResultSet_SqlPrivate Showo_Cm,Showo_WhereOther,Showo_Order,Showo_Size,Showo_Mm 'MSSQL用'================================================================' Class_Initialize 类的初始化'================================================================Private Sub Class_InitializeShowo_PageSize=10 '设定每页记录条数的默认值为10Showo_CurrPage=CheckNum(Trim(Request("Page")),1,-1) '获取当前面的值Showo_Order=">" '默认排序Showo_Size="MAX" '默认排序Showo_WhereOther="" '默认条件End Sub'================================================================' Conn 得到数据库连接对象'================================================================Public Property Let Conn(ByVal objConn)Set Showo_Conn=objConnEnd Property'================================================================' DbType 得到数据库类型'================================================================ Public Property Let DbType(ByVal strDbType)Showo_DbType=strDbTypeEnd Property'================================================================' RecType 取记录总数方法(0执行count,1自写sql语句取,2固定值)'================================================================Public Property Let RecType(ByVal intRecType)Showo_RecType=CheckNum(intRecType,0,2) End Property'================================================================' RecSql '如果RecType=1则=取记录sql语句,如果是2=数值,等于0=""'================================================================Public Property Let RecSql(ByVal strRecSql)Showo_RecSql=strRecSqlEnd Property'================================================================' RecTerm 搜索条件是否变化(0无变化,1有变化)'================================================================Public Property Let RecTerm(ByVal intRecTerm)Showo_RecTerm=CheckNum(intRecTerm,0,2) End Property'================================================================' CookieName 取得cookiename'================================================================Public Property Let CookieName(ByVal strCookieName)Showo_CookieName=strCookieNameEnd Property'================================================================' Order 排序(0顺序,1降序)'================================================================Public Property Let Order(ByVal intOrder)S_Order=CheckNum(intOrder,0,1) If S_Order=1 ThenShowo_Order="<" Showo_Size="MIN" End IfEnd Property'================================================================' PageSize 设置每一页记录条数,默认10记录'================================================================Public Property Let PageSize(ByVal intPageSize)Showo_PageSize=CheckNum(intPageSize,Showo_PageSize,-1) End Property'================================================================' JsUrl 取得showo_page.js的路径'================================================================Public Property Let JsUrl(ByVal strJsUrl)Showo_JsUrl=strJsUrlEnd Property'================================================================' Sql 取得sql所需表字段条件排序,输入:字段,表,条件,排序,主ID'================================================================Public Property Let Sql(ByVal str_sql) Showo_Sql=Split(str_sql,"$")Showo_Field=Showo_Sql(0)Showo_Table=Showo_Sql(1)Showo_Where=Showo_Sql(2)Showo_OrderBy=Showo_Sql(3)Showo_Id=Showo_Sql(4)If Len(Showo_Where)>=3 Then Showo_WhereOther=" And "&Showo_WhereShowo_Where=" Where "&Showo_WhereEnd IfIf Len(Showo_OrderBy)>3 Then Showo_OrderBy=" ORDER BY "&Showo_OrderByEnd Property'================================================================' GetRecCount 取得记录总数'================================================================Private Function GetRecCount()Select Case Showo_RecTypeCase 1GetRecCount=Showo_Conn.execute(Showo_RecSql,0,1)(0)Case 2GetRecCount=CheckNum(Showo_RecSql,0,-1)Case ElseGetRecCount=Showo_Conn.execute("SELECT Count("&Showo_Id&") FROM "&Showo_Table&" "&Showo_Where,0,1)(0)End SelectEnd Function'================================================================' RecCount 修正记录总数'================================================================Public Property Get RecCount()RecCount=Request.Cookies("ShowoPage")(Showo_CookieName)RecCount=CheckNum(RecCount,0,-1) Select Case Showo_RecTermCase 1RecCount=GetRecCount()Response.Cookies("ShowoPage")(Showo_CookieName)=RecCountCase 2RecCount=GetRecCount()Case ElseIf RecCount=0 ThenRecCount=GetRecCount()Response.Cookies("ShowoPage")(Showo_CookieName)=RecCountEnd IfEnd SelectEnd Property'================================================================' ResultSet 返回分页后的记录集'================================================================Public Property Get ResultSet()ResultSet=Null'记录总数Showo_RecCount=RecCount()'当前页If Showo_RecCount>0 Then'页数If (Showo_RecCount mod Showo_PageSize)=0 ThenShowo_PageCount=Showo_RecCount\Showo_PageSizeElseShowo_PageCount=Showo_RecCount\Showo_PageSize+1End If'当前页Showo_CurrPage=CheckNum(Showo_CurrPage,1,Showo_PageCount)Select Case Showo_DbTypeCase "AC" 'ac数据库Set Showo_Rs=Server.CreateObject ("adodb.RecordSet")ResultSet_Sql="SELECT "&Showo_Field&" FROM "&Showo_Table&" "&Showo_Where&" "&Showo_OrderByShowo_Rs.Open ResultSet_Sql,Showo_Conn,1,1,&H0001Showo_Rs.AbsolutePosition=(Showo_CurrPage-1)*Showo_PageSize+1Case "MSSQL" 'sqlserver2000数据库If Showo_CurrPage=1 ThenResultSet_Sql="SELECT TOP "&Showo_PageSize&" "&Showo_Field&" FROM "&Showo_Table&Showo_Where&" "&Showo_OrderByElseResultSet_Sql="SELECT "&Showo_Size&"("&Showo_Id&") FROM (SELECT TOP "&(Showo_CurrPage-1)*Showo_PageSize&" "&Showo_Id&" FROM "&Showo_Table&Showo_Where&" "&Showo_OrderBy&") AS tmpTable"Showo_Mm=Showo_Conn.execute(ResultSet_Sql,0,1)(0)ResultSet_Sql="SELECT TOP "&Showo_PageSize&" "&Showo_Field&" FROM "&Showo_Table&" WHERE "&Showo_Id&Showo_Order&Showo_Mm&Showo_WhereOther&" "&Showo_OrderByEnd IfSet Showo_Rs=Showo_Conn.execute(ResultSet_Sql)Case "MSSQL_SP" 'sqlserver2000数据库存储过程版Set Showo_Rs=server.CreateObject("Adodb.RecordSet")Set Showo_Cm=Server.CreateObject("Adodb.Command")Showo_Cm.CommandType=4Showo_Cm.ActiveConnection=Showo_ConnShowo_Cm.CommandText="SP_ShowoPage"Showo_Cm.parameters(1)=Showo_CurrPageShowo_Cm.parameters(2)=Showo_PageSizeShowo_Cm.parameters(3)=Showo_FieldShowo_Cm.parameters(4)=Showo_TableShowo_Cm.parameters(5)=Showo_WhereShowo_Cm.parameters(6)=Showo_WhereOtherShowo_Cm.parameters(7)=Showo_OrderByShowo_Cm.parameters(8)=Showo_IdShowo_Cm.parameters(9)=Showo_SizeShowo_Cm.parameters(10)=Showo_OrderShowo_Rs.CursorLocation=1Showo_Rs.LockType=1Showo_Rs.Open Showo_CmCase Else '其他情况按最原始的方法处理Set Showo_Rs = Server.CreateObject ("adodb.RecordSet")ResultSet_Sql="SELECT "&Showo_Field&" FROM "&Showo_Table&" "&Showo_Where&" "&Showo_OrderByShowo_Rs.Open ResultSet_Sql,Showo_Conn,1,1,&H0001Showo_Rs.AbsolutePosition=(Showo_CurrPage-1)*Showo_PageSize+1End SelectResultSet=Showo_Rs.GetRows(Showo_PageSize)Showo_Rs.closeSet Showo_Rs=NothingEnd If End Property'================================================================' 输入:检查字段,开始数字(默认数字),结束数字(为-1则不检查大小)'================================================================Private Function CheckNum(ByVal strStr,ByVal intStartNum,ByVal intEndNum)CheckNum=intStartNumIf IsNumeric(strStr) Then CheckNum=Clng(strStr) If intEndNum>-1ThenIf CheckNum<intStartNum Then CheckNum=intStartNumIf CheckNum>intEndNum Then CheckNum=intEndNumEnd IfEnd Function'================================================================' Class_Terminate 类注销'================================================================Private Sub Class_Terminate()If IsObject(Showo_Conn) Then Showo_Conn.CloseSet Showo_Conn=NothingEnd IfEnd Sub'================================================================' 上下页部分'================================================================Public Sub ShowPage()%><script Language="Javascript" type="text/Javascript" src="<%=Showo_JsUrl%>showo_page.js"></script><script Language="Javascript">ShowoPage("<table style='BORDER-COLLAPSE: collapse' borderColor='#111111' height='10' cellSpacing='0' cellPadding='0' width='95%' border='0'><tr><td vAlign='bottom' style='font-family: Verdana,宋体; font-size: 11.5px; line-height: 15px'>","</td></tr></table>","页次:<font color='red'>","</font>/",""," "," 每页<font color='red'>","</font> "," 共计:<font color='red'>","</font></td><td vAlign='bottom' align='right' style='font-family: Verdana,宋体; font-size: 11.5px; line-height: 15px'>","<font face=webdings>9</font>","<font face=webdings>7</font>","<font face=webdings>8</font>","<font face=webdings>:</font>"," 跳转:","<font color='orange'>[","]</font>","","","<font color='red'>","</font>","","",<%=RecCount()%>,<%=Showo_PageSize%>,2)</script><%End SubEnd Class%> 第三个<%@LANGUAGE = "VBscript" CODEPAGE="936"%><%Option Explicit%><!--#i nclude file="Cls_PageView.asp"--><%response.Buffer = TrueDim intDateStartintDateStart = Timer()Rem ## 打开数据库连接Rem #################################################################function f__OpenConn()Dim strDbPathDim connstrstrDbPath = "./db.mdb"connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="connstr = connstr & Server.MapPath(strDbPath)Set conn = Server.CreateObject("Adodb.Connection")conn.open connstrEnd functionRem #################################################################Rem ## 关闭数据库连接Rem #################################################################function f__CloseConn()If IsObject(conn) Thenconn.closeEnd IfSet conn = nothingEnd functionRem #################################################################Rem 获得执行时间Rem #################################################################function getTimeOver(iflag)Dim tTimeOverIf iflag = 1 ThentTimeOver = FormatNumber(Timer() - intDateStart, 6, true)getTimeOver = " 本页执行时间: " & tTimeOver & " 秒"ElsetTimeOver = FormatNumber((Timer() - intDateStart) * 1000, 3, true)getTimeOver = " 本页执行时间: " & tTimeOver & " 毫秒"End IfEnd functionRem #################################################################Dim strLocalUrlstrLocalUrl = request.ServerVariables("script_NAME")Dim intPageNowintPageNow = request.QueryString("page")Dim intPageSize, strPageInfointPageSize = 30Dim arrRecordInfo, iDim Conn, sql, sqlCountsql = "SELECT [ID], [aaaa], [bbbb], [cccc]" & _" FROM [table1]" & _" ORDER BY [ID] DESC"sqlCount = "SELECT Count([ID])" & _" FROM [table1]"f__OpenConnDim clsRecordInfoSet clsRecordInfo = New Cls_PageViewRem 记录集总数取值优先顺序: strSqlCount >> intRecordCountRem 即当 strSqlCount 有值时, intRecordCount 无作用Rem 因此, 若要手工设置记录总数, 请设置 intRecordCount, strSqlCount 留空Rem 若以上两者都没有设置, 则取 strSql 执行后的 RecordCount 属性.clsRecordInfo.intRecordCount = 2816clsRecordInfo.strSqlCount = sqlCountRem 此处因设置了 strSqlCount, 则记录总数将由此语句计算得出.Rem 设置 SQL 查询语句clsRecordInfo.strSql = sqlRem 设置每页显示数clsRecordInfo.intPageSize = intPageSizeRem 设置当前显示页clsRecordInfo.intPageNow = intPageNowRem 设置转向页面clsRecordInfo.strPageUrl = strLocalUrlRem 设置页面转向参数clsRecordInfo.strPageVar = "page"clsRecordInfo.objConn = ConnarrRecordInfo = clsRecordInfo.arrRecordInfostrPageInfo = clsRecordInfo.strPageInfoSet clsRecordInfo = nothingf__CloseConn%><html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>萧月痕通用分页类1.2 测试</title><link rel="stylesheet" href="page.css" type="text/css"></head><body bgcolor="#FFFFFF" text="#000000"><div class="PageView"><table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#FFFFFF" bordercolorlight="#CCCCCC"> <tr align="center"> <td width="60">ID</td> <td width="150">标题</td> <td width="*">内容(显示前20个字)</td> <td width="150">时间</td> </tr><%Dim bgColorIf IsArray(arrRecordInfo) ThenFor i = 0 to UBound(arrRecordInfo, 2)bgColor="#FFFFFF"if i mod 2=0 then bgColor="#DFEFFF"%> <tr bgcolor="<%=bgColor%>"> <td width="60"><%= arrRecordInfo(0, i)%></td> <td width="150"><%= arrRecordInfo(1, i)%></td> <td width="*"><%= arrRecordInfo(2, i)%></td> <td width="150"><%= arrRecordInfo(3, i)%></td> </tr><%NextEnd If%></table></div><table width="760" border="0" cellspacing="0" cellpadding="4"><tr> <td><%= strPageInfo%></td></tr><tr> <td align="center"><%= getTimeOver(0)%></td></tr></table></body></html><%@ language = "vbscript" codepage = 936%><%option explicit '强制定义变量'=========================================================================='毛虫的快速分页'mail:mc@flashado.com'主页:http://www.flashado.com'qq:69862476'本分页供初学者学习,技术上有不当之处,还请各位大侠修正'==========================================================================dim idcount'记录总数dim pages'每页条数dim pagec'总页数dim page'页码dim pagenc '每页显示的分页页码数量=pagenc*2+1pagenc=2dim pagenmax '每页显示的分页的最大页码dim pagenmin '每页显示的分页的最小页码page=clng(request("page"))dim start'程序开始的时间dim endt'程序结束的时间dim datafrom'数据表名datafrom="table1"dim conn,rsdim datapath '数据库路经dim sqlid'本页需要用到的iddim myself'本页地址myself = request.servervariables("path_info")dim sql'sql语句dim taxis'排序的语句taxis="order by id asc"dim i'用于循环的整数start=timer()datapath="db.mdb"pages=30'连接打开数据库dim dbdb="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,1idcount=rs("idcount")'获取记录总数if(idcount>0) then'如果记录总数=0,则不处理if(idcount mod pages=0)then'如果记录总数除以每页条数有余数,则=记录总数/每页条数+1pagec=int(idcount/pages)'获取总页数elsepagec=int(idcount/pages)+1'获取总页数end if'获取本页需要用到的id============================================'读取所有记录的id数值,因为只有id所以速度很快sql="select id from ["& datafrom &"] " & taxisset 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.pagesizeif rs.eof then exit for if(i=1)thensqlid=rs("id")elsesqlid=sqlid &","&rs("id")end ifrs.movenextnext'获取本页需要用到的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"><script language="javascript"><!--function gopage() {//毛虫的快速分页//mail:mc@flashado.com//主页:http://www.flashado.com//qq:69862476//本分页供初学者学习,技术上有不当之处,还请各位大侠修正window.location.href="<%=myself%>?page="+ page.value;}//--></script></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 align="center" bgcolor="#9fcb07"> <td width="9%"><strong>ID</strong></td> <td width="37%"><strong>主题</strong></td> <td width="33%"><strong>内容(显示前20个字)</strong></td> <td width="21%"><strong>时间</strong></td> </tr><%if(idcount>0 and sqlid<>"") then'如果记录总数=0,则不处理'用in刷选本页所语言的数据,仅读取本页所需的数据,所以速度快sql="select [id],[aaaa],[bbbb],[cccc] from ["& datafrom &"] where id in("& sqlid &") "&taxisset rs=server.createobject("adodb.recordset")rs.open sql,conn,0,1while(not rs.eof)'填充数据到表格%> <tr bgcolor="#ffffff"> <td align="center"><%=rs(0)%></td> <td><%=rs(1)%></td> <td><%=rs(2)%></td> <td align="center"><%=rs(3)%></td> </tr><%rs.movenextwend%> </table> <br/> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="zw"> <tr align="center"> <td align="left">共有<strong><font color="#ff6600"><%=idcount%></font></strong>条记录,<strong><font color="#ff6600"><%=page%></font></strong>/<%=pagec%>,每页<strong><font color="#ff6600"><%=pages%></font></strong>条。</td> </tr> </table> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="zw"> <tr align="center"> <td align="right"> <%'设置分页页码开始===============================pagenmin=page-pagenc'计算页码开始值pagenmax=page+pagenc'计算页码结束值if(pagenmin<1) then'如果页码开始值小于1则=1 pagenmin=1end ifif(page>1) then'如果页码大于1则显示(第一页)response.write ("<a href='"& myself &"?page=1'><font color='#000000'>第一页</font></a> ")end ifif(pagenmin>1) then'如果页码开始值大于1则显示(更前)response.write ("<a href='"& myself &"?page="& page-(pagenc*2+1) &"'><font color='#000000'>更前</font></a> ")end ifif(pagenmax>pagec) then'如果页码结束值大于总页数,则=总页数 pagenmax=pagecend iffor i = pagenmin to pagenmax'循环输出页码 if(i=page) thenresponse.write ("<font color='#ff6600'><strong>"& i &"</strong></font> ") elseresponse.write ("[ <a href="& myself &"?page="& i &"><font color='#000000'>"& i &"</font></a> ] ") end ifnextif(pagenmax<pagec) then'如果页码结束值小于总页数则显示(更后)response.write ("<a href='"& myself &"?page="& page+(pagenc*2+1) &"'><font color='#000000'>更后</font></a> ")end ifif(page<pagec) then'如果页码小于总页数则显示(最后页)response.write ("<a href='"& myself &"?page="& pagec &"'><font color='#000000'>最后页</font></a> ")end if'设置分页页码结束===============================%>转到<input name="page" type="text" value="<%=page%>" size="5">页<input type="button" name="submit" value="跳转" onclick="gopage()"></td> </tr> </table> <%end if%> <br/> <table width="90%" border="0" align="center" cellpadding="2" cellspacing="0" class="zw"> <tr> <td align="center"><%endt=timer()rs.closeset rs=nothingconn.closeset conn=nothing%> <%=formatnumber((endt-start)*1000,3)%>毫秒 <br/> 这里可能是0毫秒,但这并不是说这东西真正的0。 </td> </tr></table><br/></td> </tr> </table></td> </tr></table></body></html><%@LANGUAGE="VBscript" CODEPAGE="936"%><%Rem ================================================================================================Rem = File Name : mlzpage.aspRem = Description : ASP + Access2000 高效分页法Rem = Trait : 可承受百万以上数据,倒序分页效率不变Rem = Power by : NB联盟--mackyliu (才子,风流才子) 另感谢联盟炼子兄弟提供记录指针算法Rem = QQ:5151378 MSN:mackylxf@hotmail.com Web:http://www.54caizi.comRem = Last Modify : 2004/09/20 NightRem = Revision : 1.3 BetaRem ================================================================================================On Error Resume Nextdim startime,endtimestartime=timer()'连接数据库dim db,conn,rsdb = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("./db.mdb")set conn = server.createobject("adodb.connection")set rs = server.createobject("adodb.recordset")conn.open db%><%'**************'分页导航栏函数'输出wzpage值'**************Function pagination(pagecount) Dim wzpage,wzpagecount,pagenum,boardid boardid = Request.QueryString("board_id") If boardid = 0 Then boardid = 1 If Len(Request.QueryString("page"))<>0 Then wzpage = clng(Request.QueryString("page")) Else wzpage =1 End If If wzpage <= 0 Then wzpage =1 pagenum = (wzpage \ 10)*10+1 If wzpage mod 10 = 0 Then pagenum = (wzpage \ 10)*10-9 If wzpage > 10 Then Response.Write ("<font face=""webdings"">") Response.Write ("<a href="/blog/"?board_id="& boardid &"&page=1"" title=""首页"">9</a>")Response.Write ("<a href="/blog/"?board_id="& boardid &"&page="& pagenum-1 &""" title=""前十页"">7</a>") Response.Write ("</font>") End If For pagenum = pagenum To pagenum + 9 If pagenum = wzpage Then Response.Write ("<font color=""#ff0000"">") Response.Write (" ["& pagenum &"] ") Response.Write ("</font>") Else Response.Write (" <a href="/blog/"?board_id="& boardid &"&page="& pagenum &""">") Response.Write ("["& pagenum &"]") Response.Write ("</a> ")End If If pagenum >= pagecount Then Exit For Next If wzpage < (pagecount - (pagecount \ 10)) Then Response.Write ("<font face=""webdings"">") Response.Write ("<a href="/blog/"?board_id="& boardid &"&page="& pagenum &""" title=""后十页"">8</a>")Response.Write ("<a href="/blog/"?board_id="& boardid &"&page="& pagecount &""" title=""末页"">:</a>") Response.Write ("</font>") End IfEnd Function%><%dim rssql,getstringgetstring = clng(request.querystring("board_id"))if getstring = 0 then getstring = 1'******************************************'取文章总数及每页重复显示条数,准备分页'wzcount 文章总数'wzrep 重复显示条数'wzpage 分页参数id'wzpagecount 总页数'******************************************dim wzcount,wzrep,wzpage,wzpagecount,wzpagerep,boardstrwzrep = 30'rssql = "select count(id) from `table1`"'rs.open rssql,conn,0,1,&h0001wzcount = conn.execute ("select count(id) from `table1`",0,1)(0)'rs.closewzpagecount = abs(int(-abs(wzcount/wzrep)))wzpage = clng(request.querystring("page"))if len(wzpage) = 0 or wzpage = 0 then wzpage = 1%><html><head><title>分页测试</title><meta http-equiv="content-type" content="text/html; charset=gb2312"><link rel="stylesheet" href="page.css" type="text/css"></head><body><table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc"> <tr align="center"> <td width="60">ID</td> <td width="150">标题</td> <td width="*">内容(显示前20个字)</td> <td width="150">时间</td> </tr> <%'取文章列表rssql = "select id,aaaa,bbbb,cccc from `table1`"rs.open rssql,conn,1,1,&h0001'根据分页参数获取当前页面纪录rs.absoluteposition=rs.absoluteposition+((abs(wzpage)-1)*wzrep)'显示文章标题列表if rs.eof or rs.bof then%><tr> <td >暂无记录</td> </tr><% elsedim i,bgcolorfor i = 0 to wzrep-1if rs.eof then exit for'while not rs.eof and i <= wzrepbgColor="#FFFFFF"if i mod 2=0 then bgColor="#DFEFFF"%> <tr bgcolor="<%=bgColor%>"> <td width="60"><%=rs(0)%></td> <td width="150"><%=rs(1)%></td> <td width="*"><%=left(rs(2),20)%></td> <td width="150"><%=rs(3)%></td> </tr><%rs.movenext'i=i+1'wendnextend if%></table><table width="760" border="0" cellspacing="2" cellpadding="2" align="center"> <tr> <td align="left" width="200">共<font color=red><%= wzcount%></font>条 <font color=red><%= wzrep%></font>/页 共<font color=red><%= wzpagecount%></font>页</td><td align="right"> <%= pagination(wzpagecount)%></td> </tr></table><table width="760" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td align="center"> <%endtime=timer()%> 本页面执行时间:<%=formatnumber((endtime-startime)*1000,3)%>毫秒</td> </tr></table></body></html><%'释放资源rs.closeset rs = nothingconn.closeset conn = nothing%> 第四个<%@language="vbscript" codepage="936"%><%'定义数据连接option expliciton error resume nextdim startime,endtimestartime=timer()dim db,conn,rsdb = "provider=microsoft.jet.oledb.4.0;data source=" & server.mappath("./db.mdb")set conn = server.createobject("adodb.connection")set rs = server.createobject("adodb.recordset")conn.open db%><%'**************'分页导航栏函数'输出wzpage值'**************Function pagination(pagecount) Dim wzpage,wzpagecount,pagenum,boardid boardid = Request.QueryString("board_id") If boardid = 0 Then boardid = 1 If Len(Request.QueryString("page"))<>0 Then wzpage = clng(Request.QueryString("page")) Else wzpage =1 End If If wzpage <= 0 Then wzpage =1 pagenum = (wzpage \ 10)*10+1 If wzpage mod 10 = 0 Then pagenum = (wzpage \ 10)*10-9 If wzpage > 10 Then Response.Write ("<font face=""webdings"">") Response.Write ("<a href="/blog/"?board_id="& boardid &"&page=1"" title=""首页"">9</a>")Response.Write ("<a href="/blog/"?board_id="& boardid &"&page="& pagenum-1 &""" title=""前十页"">7</a>") Response.Write ("</font>") End If For pagenum = pagenum To pagenum + 9 If pagenum = wzpage Then Response.Write ("<font color=""#ff0000"">") Response.Write (" ["& pagenum &"] ") Response.Write ("</font>") Else Response.Write (" <a href="/blog/"?board_id="& boardid &"&page="& pagenum &""">") Response.Write ("["& pagenum &"]") Response.Write ("</a> ")End If If pagenum >= pagecount Then Exit For Next If wzpage < (pagecount - (pagecount \ 10)) Then Response.Write ("<font face=""webdings"">") Response.Write ("<a href="/blog/"?board_id="& boardid &"&page="& pagenum &""" title=""后十页"">8</a>")Response.Write ("<a href="/blog/"?board_id="& boardid &"&page="& pagecount &""" title=""末页"">:</a>") Response.Write ("</font>") End IfEnd Function%><%dim rssql,getstringgetstring = clng(request.querystring("board_id"))if getstring = 0 then getstring = 1'******************************************'取文章总数及每页重复显示条数,准备分页'wzcount 文章总数'wzrep 重复显示条数'wzpage 分页参数id'wzpagecount 总页数'******************************************dim wzcount,wzrep,wzpage,wzpagecount,wzpagerep,boardstrwzrep = 30'rssql = "select count(id) from `table1`"'rs.open rssql,conn,0,1,&h0001wzcount = conn.execute ("select count(id) from `table1`",0,1)(0)'rs.closewzpagecount = abs(int(-abs(wzcount/wzrep)))wzpage = clng(request.querystring("page"))if len(wzpage) = 0 or wzpage = 0 then wzpage = 1%><html><head><title>分页测试</title><meta http-equiv="content-type" content="text/html; charset=gb2312"><link rel="stylesheet" href="page.css" type="text/css"></head><body><table width="760" border="1" cellspacing="0" cellpadding="4" align="center" bordercolordark="#ffffff" bordercolorlight="#cccccc"> <tr align="center"> <td width="60">ID</td> <td width="150">标题</td> <td width="*">内容(显示前20个字)</td> <td width="150">时间</td> </tr> <%'取文章列表rssql = "select id,aaaa,bbbb,cccc from `table1` order by id desc"rs.open rssql,conn,1,1,&h0001'根据分页参数获取当前页面纪录rs.absoluteposition=rs.absoluteposition+((abs(wzpage)-1)*wzrep)'显示文章标题列表if rs.eof or rs.bof then%><tr> <td >暂无记录</td> </tr><% elsedim i,bgcolorfor i = 0 to wzrep-1if rs.eof then exit for'while not rs.eof and i <= wzrepbgColor="#FFFFFF"if i mod 2=0 then bgColor="#DFEFFF"%> <tr bgcolor="<%=bgColor%>"> <td width="60"><%=rs(0)%></td> <td width="150"><%=rs(1)%></td> <td width="*"><%=left(rs(2),20)%></td> <td width="150"><%=rs(3)%></td> </tr><%rs.movenext'i=i+1'wendnextend if%></table><table width="760" border="0" cellspacing="2" cellpadding="2" align="center"> <tr> <td align="left" width="200">共<font color=red><%= wzcount%></font>条 <font color=red><%= wzrep%></font>/页 共<font color=red><%= wzpagecount%></font>页</td><td align="right"> <%= pagination(wzpagecount)%></td> </tr></table><table width="760" border="0" align="center" cellpadding="2" cellspacing="2"> <tr> <td align="center"> <%endtime=timer()%> 本页面执行时间:<%=formatnumber((endtime-startime)*1000,3)%>毫秒</td> </tr></table></body></html><%'释放资源rs.closeset rs = nothingconn.closeset conn = nothing%> 第五个<%'===================================================================='= ASP分页类'= Copyright (c) 2006 - 2007 Fhuoyun All Rights Reserved.'=-------------------------------------------------------------------'= 最后更新:fhuoyun'= 最后日期:下午 05:13 2006-12-13'==================================================================== Class cls_pagelist '************************************************************************************* '页面数据 '************************************************************************************* Public Function CutPageList(iSQL,iCurrentPage,iPageSize) On Error Resume Next Err.Clear Set Rs=Server.CreateObject("adodb.recordSet") Rs.Open iSQL,Conn,1,1 If Not rs.Eof And Not rs.bof Then Rs.AbsolutePosition=Rs.AbsolutePosition+((Abs(iCurrentPage)-1)*iPageSize) CutPageList=Rs.GetRows(iPageSize) Else CutPageList="" End If Rs.Close Set Rs=Nothing If Err Then Response.clear ErrMsg="在执行以下语句3:<br>" ErrMsg=ErrMsg&" <font color=800000>"&iSQL&"</font><br>" ErrMsg=ErrMsg&"时,发生以下错误1:<br>" ErrMsg=ErrMsg&" <font color=800000>"&Err.Description&"</font>" Response.Write ErrMsg End If End Function '************************************************************************************* '页脚分页 '************************************************************************************* Public Function PageList (PageCount,iCurrentPage,FieldName,FieldValue) Dim Url Dim PageRoot Dim PageFoot Dim OutStr Dim i If IsArray(FieldName) And IsArray(FieldValue) Then Dim page_i For page_i=0 to Ubound(FieldName) Url=Url&"&"&Cstr(FieldName(page_i))&"="&Cstr(FieldValue(page_i)) Next End If If CLng(iCurrentPage)<=0 Then iCurrentPage=1 ElseIf CLng(iCurrentPage)>CLng(PageCount) Then iCurrentPage=PageCount End if If iCurrentPage-2<=1 Then PageRoot=1 Else PageRoot=iCurrentPage-2 End If If iCurrentPage+2>=PageCount Then PageFoot=PageCount Else PageFoot=iCurrentPage+2 End If OutStr="<div id=""pageList""><span class=""list"">共 "&PageCount&" 页</span> " If iCurrentPage<=1 Then OutStr=OutStr&"<span class=""hidden"">«</span> " OutStr=OutStr&"<span class=""hidden""><</span> " Else OutStr=OutStr&"<span class=""first""><a href=""?page=1" OutStr=OutStr&Url OutStr=OutStr&""" title=""首页"">«</a></span> " OutStr=OutStr&"<span class=""list""><a href=""?page="&iCurrentPage-1 OutStr=OutStr&Url OutStr=OutStr&""" title=""上页""><</a></span> " End If For i=PageRoot To PageFoot If i=Cint(iCurrentPage) Then OutStr=OutStr&"<span class=""current"">"&i&"</span> " Else OutStr=OutStr&"<span class=""list""><a href=""?page="&Cstr(i) OutStr=OutStr&Url OutStr=OutStr&""">"&i&"</a></span> " End If If i=PageCount Then Exit For Next If Cint(iCurrentPage)=Cint(PageCount) Then OutStr=OutStr&"<span class=""hidden"">></span> " OutStr=OutStr&"<span class=""hidden"">»</span> " Else OutStr=OutStr&"<span class=""list""><a href=""?page="&iCurrentPage+1 OutStr=OutStr&Url OutStr=OutStr&""" title=""下页"">></a></span> " OutStr=OutStr&"<span class=""last""><a href=""?page="&PageCount OutStr=OutStr&Url OutStr=OutStr&""" title=""尾页"">»</a></span> " End If If PageCount > 0 Then OutStr=OutStr&" <input type=""text"" size=""3"" value="""&iCurrentPage&""" onmouseover=""this.focus();this.select()"" id=""PGNumber"" /> <input type=""button"" value=""GO"" onclick=""if (document.getElementById('PGNumber').value>0 && document.getElementById('PGNumber').value<="&PageCount&"){window.location='?page='+document.getElementById('PGNumber').value+'"&Url&"'}"" />" End If OutStr = OutStr & "</div>" PageList=OutStr End Function End Class%>