• 几个ASP的分页类


    第一个<%
    Rem ************************************************
    Rem ** 作者: 萧月痕(xiaoyuehen)
    Rem ** ASP 通用分页类
    Rem ** 版本: 1.2.00
    Rem ** 最后修改: 2005-4-18
    Rem ** 版权说明: 在文档完整的前提下可任意复制, 传播.
    Rem ** 联系作者: xiaoyuehen(at)msn.com
    Rem ************************************************

    Class Cls_PageView
    Private sbooInitState
    Private sstrPageUrl
    Private sstrPageVar
    Private sstrSql
    Private sstrSqlCount

    Private sintRecordCount
    Private sintPageSize
    Private sintPageNow
    Private sintPageMax

    Private sobjConn

    Private sstrPageInfo

    Private Sub Class_Initialize
    Call ClearVars()
    End Sub

    Private Sub class_terminate()
    Set sobjConn = nothing
    End Sub

    Public Sub ClearVars()
    sbooInitState = False
    sstrPageUrl = ""
    sstrPageVar = "page"

    sintRecordCount = 0
    sintPageSize = 20
    sintPageNow = 0
    sintPageMax = 0
    End Sub

    Private Sub ClearMainVars()
    sstrSql = ""
    End Sub

    Rem ## SQL语句
    Public Property Let strSQL(Value)
    sstrSql = Value
    End Property

    Rem ## SQL语句
    Public Property Let strSQLCount(Value)
    sstrSqlCount = Value
    End Property

    Rem ## 转向地址
    Public Property Let strPageurl(/blog/Value)
    sstrPageUrl = Value
    End Property

    Rem ## 每页显示的记录条数
    Public Property Let intPageSize(Value)
    sintPageSize = toNum(Value, 20)
    End Property

    Rem ## 数据库连接对象
    Public Property Let objConn(Value)
    Set sobjConn = Value
    End Property

    Rem ## 当前页
    Public Property Let intPageNow(Value)
    sintPageNow = toNum(Value, 1)
    End Property

    Rem ## 设置记录总数
    Public Property Let intRecordCount(Value)
    sintRecordCount = toNum(Value, -1)
    If sintRecordCount < 0 Then sintRecordCount = -1
    End Property

    Rem ## 页面参数
    Public Property Let strPageVar(Value)
    sstrPageVar = Value
    End Property

    Rem ## 获得当前页
    Public Property Get intPageNow()
    intPageNow = singPageNow
    End Property

    Rem ## 分页信息
    Public Property Get strPageInfo()
    strPageInfo = sstrPageInfo
    End Property

    Rem ## 取得记录集, 二维数组或字串, 在进行循环输出时必须用 IsArray() 判断
    Public Property Get arrRecordInfo()
    Call InitClass()
    If Not sbooInitState Then
    Response.Write("分页类初始化失败, 请检查各参数情况")
    Exit Property
    End If

    Dim rs, sql
    sql = sstrSql

    Set rs = Server.CreateObject("Adodb.RecordSet")

    Rem 若记录数统计语句不为空, 则取语句执行后第一个字段值作为记录数
    If sstrSqlCount <> "" Then
    rs.Open sstrSqlCount, sobjConn, 1, 1
    If Not(rs.eof or rs.bof) Then
    sintRecordCount = rs(0)
    Else
    sintRecordCount = 0
    End If
    rs.Close
    End If

    rs.open sql, sobjConn, 1, 1

    Rem 若无记录统计语句且未设定记录总数, 则由记录集RecordCount属性得出.
    If sintRecordCount < 0 Then
    sintRecordCount = rs.RecordCount
    End If
    If sintRecordCount < 0 Then sintRecordCount = 0

    '生成分页信息
    Call InitPageInfo()

    If Not(rs.eof or rs.bof) Then
    rs.PageSize = sintPageSize
    rs.AbsolutePage = sintPageNow
    If Not(rs.eof or rs.bof) Then
    arrRecordInfo = rs.getrows(sintPageSize)
    Else
    arrRecordInfo = ""
    End If
    Else
    arrRecordInfo = ""
    End If
    rs.close
    Set rs = nothing

    Call ClearMainVars()
    End Property

    Rem ## 初始化分页信息
    Private Sub InitPageInfo()
    sstrPageInfo = ""

    Dim surl
    surl = sstrPageUrl
    If Instr(1, surl, "?", 1) > 0 Then
    surl = surl & "&" & sstrPageVar & "="
    Else
    surl = surl & "?" & sstrPageVar & "="
    End If

    If sintPageNow <= 0 Then sintPageNow = 1
    If sintRecordCount mod sintPageSize = 0 Then
    sintPageMax = sintRecordCount \ sintPageSize
    Else
    sintPageMax = sintRecordCount \ sintPageSize + 1
    End If
    If sintPageNow > sintPageMax Then sintPageNow = sintPageMax

    If sintPageNow <= 1 then
    sstrPageInfo = "首页 上一页"
    Else
    sstrPageInfo = sstrPageInfo & " <a href=""" & surl & "1"">首页</a>"
    sstrPageInfo = sstrPageInfo & " <a href=""" & surl & (sintPageNow - 1) & """>上一页</a>"
    End If

    If sintPageMax - sintPageNow < 1 then
    sstrPageInfo = sstrPageInfo & " 下一页 末页 "
    Else
    sstrPageInfo = sstrPageInfo & " <a href=""" & surl & (sintPageNow + 1) & """>下一页</a> "
    sstrPageInfo = sstrPageInfo & " <a href=""" & surl & sintPageMax & """>末页</a> "
    End If

    sstrPageInfo = sstrPageInfo & " 页次:<strong><font color=""#990000"">" & sintPageNow & "</font> / " & sintPageMax & " </strong>"
    sstrPageInfo = sstrPageInfo & " 共 <strong>" & sintRecordCount & "</strong> 条记录 <strong>" & sintPageSize & "</strong> 条/页 "
    End Sub

    Rem ## 长整数转换
    Private function toNum(s, Default)
    s = s & ""
    If s <> "" And IsNumeric(s) Then
    toNum = CLng(s)
    Else
    toNum = Default
    End If
    End function

    Rem ## 类初始化
    Public Sub InitClass()
    sbooInitState = True
    If Not(IsObject(sobjConn)) Then
    sbooInitState = False

    response.write("数据库连接未指定")
    response.End()
    End If
    If Trim(sstrSql) = "" Then
    sbooInitState = False

    response.write("SQL语句未指定")
    response.End()
    End If
    sintPageSize = toNum(sintPageSize, 20)
    If (sintPageSize < 1) Or (sintPageSize > 100) Then
    sbooInitState = False

    response.write("每页记集数未设置或不符合规则(1 - 100)")
    response.End()
    End If
    sintPageNow = toNum(sintPageNow, 1)

    sintRecordCount = -1
    End Sub
    End 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_ShowoPage
    Private Showo_PageSize,Showo_CurrPage
    Private Showo_Conn,Showo_DbType,Showo_RecType,Showo_RecSql,Showo_RecTerm,Showo_CookieName
    Private S_Order,Showo_JsUrl
    Private Showo_Sql,Showo_Field,Showo_Table,Showo_Where,Showo_OrderBy,Showo_Id
    Private Showo_RecCount,Showo_PageCount,ResultSet_Sql
    Private Showo_Cm,Showo_WhereOther,Showo_Order,Showo_Size,Showo_Mm 'MSSQL用

    '================================================================
    ' Class_Initialize 类的初始化
    '================================================================
    Private Sub Class_Initialize
    Showo_PageSize=10 '设定每页记录条数的默认值为10
    Showo_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=objConn
    End Property

    '================================================================
    ' DbType 得到数据库类型
    '================================================================
    Public Property Let DbType(ByVal strDbType)
    Showo_DbType=strDbType
    End 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=strRecSql
    End 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=strCookieName
    End Property

    '================================================================
    ' Order 排序(0顺序,1降序)
    '================================================================
    Public Property Let Order(ByVal intOrder)
    S_Order=CheckNum(intOrder,0,1)
    If S_Order=1 Then
    Showo_Order="<"
    Showo_Size="MIN"
    End If
    End 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=strJsUrl
    End 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_Where
    Showo_Where=" Where "&Showo_Where
    End If
    If Len(Showo_OrderBy)>3 Then Showo_OrderBy=" ORDER BY "&Showo_OrderBy
    End Property

    '================================================================
    ' GetRecCount 取得记录总数
    '================================================================
    Private Function GetRecCount()
    Select Case Showo_RecType
    Case 1
    GetRecCount=Showo_Conn.execute(Showo_RecSql,0,1)(0)
    Case 2
    GetRecCount=CheckNum(Showo_RecSql,0,-1)
    Case Else
    GetRecCount=Showo_Conn.execute("SELECT Count("&Showo_Id&") FROM "&Showo_Table&" "&Showo_Where,0,1)(0)
    End Select
    End Function

    '================================================================
    ' RecCount 修正记录总数
    '================================================================
    Public Property Get RecCount()
    RecCount=Request.Cookies("ShowoPage")(Showo_CookieName)
    RecCount=CheckNum(RecCount,0,-1)
    Select Case Showo_RecTerm
    Case 1
    RecCount=GetRecCount()
    Response.Cookies("ShowoPage")(Showo_CookieName)=RecCount
    Case 2
    RecCount=GetRecCount()
    Case Else
    If RecCount=0 Then
    RecCount=GetRecCount()
    Response.Cookies("ShowoPage")(Showo_CookieName)=RecCount
    End If
    End Select
    End Property

    '================================================================
    ' ResultSet 返回分页后的记录集
    '================================================================
    Public Property Get ResultSet()
    ResultSet=Null
    '记录总数
    Showo_RecCount=RecCount()
    '当前页
    If Showo_RecCount>0 Then
    '页数
    If (Showo_RecCount mod Showo_PageSize)=0 Then
    Showo_PageCount=Showo_RecCount\Showo_PageSize
    Else
    Showo_PageCount=Showo_RecCount\Showo_PageSize+1
    End If
    '当前页
    Showo_CurrPage=CheckNum(Showo_CurrPage,1,Showo_PageCount)
    Select Case Showo_DbType
    Case "AC" 'ac数据库
    Set Showo_Rs=Server.CreateObject ("adodb.RecordSet")
    ResultSet_Sql="SELECT "&Showo_Field&" FROM "&Showo_Table&" "&Showo_Where&" "&Showo_OrderBy
    Showo_Rs.Open ResultSet_Sql,Showo_Conn,1,1,&H0001
    Showo_Rs.AbsolutePosition=(Showo_CurrPage-1)*Showo_PageSize+1
    Case "MSSQL" 'sqlserver2000数据库
    If Showo_CurrPage=1 Then
    ResultSet_Sql="SELECT TOP "&Showo_PageSize&" "&Showo_Field&" FROM "&Showo_Table&Showo_Where&" "&Showo_OrderBy
    Else
    ResultSet_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_OrderBy
    End If
    Set 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=4
    Showo_Cm.ActiveConnection=Showo_Conn
    Showo_Cm.CommandText="SP_ShowoPage"
    Showo_Cm.parameters(1)=Showo_CurrPage
    Showo_Cm.parameters(2)=Showo_PageSize
    Showo_Cm.parameters(3)=Showo_Field
    Showo_Cm.parameters(4)=Showo_Table
    Showo_Cm.parameters(5)=Showo_Where
    Showo_Cm.parameters(6)=Showo_WhereOther
    Showo_Cm.parameters(7)=Showo_OrderBy
    Showo_Cm.parameters(8)=Showo_Id
    Showo_Cm.parameters(9)=Showo_Size
    Showo_Cm.parameters(10)=Showo_Order
    Showo_Rs.CursorLocation=1
    Showo_Rs.LockType=1
    Showo_Rs.Open Showo_Cm
    Case Else '其他情况按最原始的方法处理
    Set Showo_Rs = Server.CreateObject ("adodb.RecordSet")
    ResultSet_Sql="SELECT "&Showo_Field&" FROM "&Showo_Table&" "&Showo_Where&" "&Showo_OrderBy
    Showo_Rs.Open ResultSet_Sql,Showo_Conn,1,1,&H0001
    Showo_Rs.AbsolutePosition=(Showo_CurrPage-1)*Showo_PageSize+1
    End Select
    ResultSet=Showo_Rs.GetRows(Showo_PageSize)
    Showo_Rs.close
    Set Showo_Rs=Nothing
    End If  
    End Property
    '================================================================
    ' 输入:检查字段,开始数字(默认数字),结束数字(为-1则不检查大小)
    '================================================================
    Private Function CheckNum(ByVal strStr,ByVal intStartNum,ByVal intEndNum)
    CheckNum=intStartNum
    If IsNumeric(strStr) Then CheckNum=Clng(strStr)        
    If intEndNum>-1Then
    If CheckNum<intStartNum Then CheckNum=intStartNum
    If CheckNum>intEndNum Then CheckNum=intEndNum
    End If
    End Function

    '================================================================
    ' Class_Terminate 类注销
    '================================================================
    Private Sub Class_Terminate()
    If IsObject(Showo_Conn) Then
    Showo_Conn.Close
    Set Showo_Conn=Nothing
    End If
    End 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 Sub

    End Class%>


    第三个<%@LANGUAGE = "VBscript" CODEPAGE="936"%>
    <%Option Explicit%>
    <!--#i nclude file="Cls_PageView.asp"-->
    <%
    response.Buffer = True
    Dim intDateStart
    intDateStart = Timer()

    Rem ## 打开数据库连接
    Rem #################################################################
    function f__OpenConn()
    Dim strDbPath
    Dim connstr
    strDbPath = "./db.mdb"
    connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
    connstr = connstr & Server.MapPath(strDbPath)
    Set conn = Server.CreateObject("Adodb.Connection")
    conn.open connstr
    End function
    Rem #################################################################

    Rem ## 关闭数据库连接
    Rem #################################################################
    function f__CloseConn()
    If IsObject(conn) Then
    conn.close
    End If
    Set conn = nothing
    End function
    Rem #################################################################

    Rem 获得执行时间
    Rem #################################################################
    function getTimeOver(iflag)
    Dim tTimeOver
    If iflag = 1 Then
    tTimeOver = FormatNumber(Timer() - intDateStart, 6, true)
    getTimeOver = " 本页执行时间: " & tTimeOver & " 秒"
    Else
    tTimeOver = FormatNumber((Timer() - intDateStart) * 1000, 3, true)
    getTimeOver = " 本页执行时间: " & tTimeOver & " 毫秒"
    End If
    End function
    Rem #################################################################

    Dim strLocalUrl
    strLocalUrl = request.ServerVariables("script_NAME")

    Dim intPageNow
    intPageNow = request.QueryString("page")

    Dim intPageSize, strPageInfo
    intPageSize = 30

    Dim arrRecordInfo, i
    Dim Conn, sql, sqlCount
    sql = "SELECT [ID], [aaaa], [bbbb], [cccc]" & _
    " FROM [table1]" & _
    " ORDER BY [ID] DESC"
    sqlCount = "SELECT Count([ID])" & _
    " FROM [table1]"
    f__OpenConn
    Dim clsRecordInfo
    Set clsRecordInfo = New Cls_PageView

    Rem 记录集总数取值优先顺序: strSqlCount >>  intRecordCount
    Rem 即当 strSqlCount 有值时, intRecordCount 无作用
    Rem 因此, 若要手工设置记录总数, 请设置 intRecordCount, strSqlCount 留空
    Rem 若以上两者都没有设置, 则取 strSql 执行后的 RecordCount 属性.
    clsRecordInfo.intRecordCount = 2816
    clsRecordInfo.strSqlCount = sqlCount
    Rem 此处因设置了 strSqlCount, 则记录总数将由此语句计算得出.

    Rem 设置 SQL 查询语句
    clsRecordInfo.strSql = sql

    Rem 设置每页显示数
    clsRecordInfo.intPageSize = intPageSize

    Rem 设置当前显示页
    clsRecordInfo.intPageNow = intPageNow

    Rem 设置转向页面
    clsRecordInfo.strPageUrl = strLocalUrl

    Rem 设置页面转向参数
    clsRecordInfo.strPageVar = "page"

    clsRecordInfo.objConn = Conn
    arrRecordInfo = clsRecordInfo.arrRecordInfo
    strPageInfo = clsRecordInfo.strPageInfo
    Set clsRecordInfo = nothing
    f__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 bgColor
    If IsArray(arrRecordInfo) Then
    For 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>
    <%
    Next
    End 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+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"
    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">
    <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 &") "&taxis
    set rs=server.createobject("adodb.recordset")
    rs.open sql,conn,0,1

    while(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.movenext
    wend
    %>
      </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=1
    end if

    if(page>1) then'如果页码大于1则显示(第一页)
    response.write ("<a href='"& myself &"?page=1'><font color='#000000'>第一页</font></a> ")
    end if
    if(pagenmin>1) then'如果页码开始值大于1则显示(更前)
    response.write ("<a href='"& myself &"?page="& page-(pagenc*2+1) &"'><font color='#000000'>更前</font></a> ")
    end if

    if(pagenmax>pagec) then'如果页码结束值大于总页数,则=总页数
        pagenmax=pagec
    end if

    for i = pagenmin to pagenmax'循环输出页码
        if(i=page) then
    response.write ("<font color='#ff6600'><strong>"& i &"</strong></font> ")
        else
    response.write ("[ <a href="& myself &"?page="& i &"><font color='#000000'>"& i &"</font></a> ] ")
        end if
    next
    if(pagenmax<pagec) then'如果页码结束值小于总页数则显示(更后)
    response.write ("<a href='"& myself &"?page="& page+(pagenc*2+1) &"'><font color='#000000'>更后</font></a> ")
    end if
    if(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.close
    set rs=nothing
    conn.close
    set 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.asp
    Rem = Description : ASP + Access2000 高效分页法
    Rem = Trait : 可承受百万以上数据,倒序分页效率不变
    Rem = Power by : NB联盟--mackyliu (才子,风流才子) 另感谢联盟炼子兄弟提供记录指针算法
    Rem = QQ:5151378 MSN:mackylxf@hotmail.com Web:http://www.54caizi.com
    Rem = Last Modify : 2004/09/20 Night
    Rem = Revision : 1.3 Beta
    Rem ================================================================================================

    On Error Resume Next
    dim startime,endtime
    startime=timer()

    '连接数据库
    dim db,conn,rs
    db = "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 If
    End Function
    %>


    <%
    dim rssql,getstring
    getstring = clng(request.querystring("board_id"))
    if getstring = 0 then getstring = 1

    '******************************************
    '取文章总数及每页重复显示条数,准备分页
    'wzcount 文章总数
    'wzrep 重复显示条数
    'wzpage 分页参数id
    'wzpagecount 总页数
    '******************************************
    dim wzcount,wzrep,wzpage,wzpagecount,wzpagerep,boardstr
    wzrep = 30
    'rssql = "select count(id) from `table1`"
    'rs.open rssql,conn,0,1,&h0001
    wzcount = conn.execute ("select count(id) from `table1`",0,1)(0)
    'rs.close
    wzpagecount = 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>
    <% else
    dim i,bgcolor
    for i = 0 to wzrep-1
    if rs.eof then exit for
    'while not rs.eof and i <= wzrep
    bgColor="#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
    'wend
    next
    end 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.close
    set rs = nothing
    conn.close
    set conn = nothing
    %>


    第四个<%@language="vbscript" codepage="936"%>
    <%
    '定义数据连接
    option explicit
    on error resume next
    dim startime,endtime
    startime=timer()
    dim db,conn,rs
    db = "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 If
    End Function
    %>


    <%
    dim rssql,getstring
    getstring = clng(request.querystring("board_id"))
    if getstring = 0 then getstring = 1

    '******************************************
    '取文章总数及每页重复显示条数,准备分页
    'wzcount 文章总数
    'wzrep 重复显示条数
    'wzpage 分页参数id
    'wzpagecount 总页数
    '******************************************
    dim wzcount,wzrep,wzpage,wzpagecount,wzpagerep,boardstr
    wzrep = 30
    'rssql = "select count(id) from `table1`"
    'rs.open rssql,conn,0,1,&h0001
    wzcount = conn.execute ("select count(id) from `table1`",0,1)(0)
    'rs.close
    wzpagecount = 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>
    <% else
    dim i,bgcolor
    for i = 0 to wzrep-1
    if rs.eof then exit for
    'while not rs.eof and i <= wzrep
    bgColor="#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
    'wend
    next
    end 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.close
    set rs = nothing
    conn.close
    set 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&"&nbsp;&nbsp;<font color=800000>"&iSQL&"</font><br>"
       ErrMsg=ErrMsg&"时,发生以下错误1:<br>"
       ErrMsg=ErrMsg&"&nbsp;&nbsp;<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&"&amp;"&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>&nbsp;"
      
      
       If iCurrentPage<=1 Then
        OutStr=OutStr&"<span class=""hidden"">&laquo;</span>&nbsp;"
        OutStr=OutStr&"<span class=""hidden"">&lt;</span>&nbsp;"
       Else
        OutStr=OutStr&"<span class=""first""><a href=""?page=1"
        OutStr=OutStr&Url
        OutStr=OutStr&""" title=""首页"">&laquo;</a></span>&nbsp;"
        OutStr=OutStr&"<span class=""list""><a href=""?page="&iCurrentPage-1
        OutStr=OutStr&Url
        OutStr=OutStr&""" title=""上页"">&lt;</a></span>&nbsp;"
       End If
      
      For i=PageRoot To PageFoot
       If i=Cint(iCurrentPage) Then
        OutStr=OutStr&"<span class=""current"">"&i&"</span>&nbsp;"
       Else
        OutStr=OutStr&"<span class=""list""><a href=""?page="&Cstr(i)
        OutStr=OutStr&Url
        OutStr=OutStr&""">"&i&"</a></span>&nbsp;"
       End If
       If i=PageCount Then Exit For
      Next

       If Cint(iCurrentPage)=Cint(PageCount) Then
        OutStr=OutStr&"<span class=""hidden"">&gt;</span>&nbsp;"
        OutStr=OutStr&"<span class=""hidden"">&raquo;</span>&nbsp;"
       Else
        OutStr=OutStr&"<span class=""list""><a href=""?page="&iCurrentPage+1
        OutStr=OutStr&Url
        OutStr=OutStr&""" title=""下页"">&gt;</a></span>&nbsp;"
        OutStr=OutStr&"<span class=""last""><a href=""?page="&PageCount
        OutStr=OutStr&Url
        OutStr=OutStr&""" title=""尾页"">&raquo;</a></span>&nbsp;"
       End If
      
      If PageCount > 0 Then
       OutStr=OutStr&"&nbsp;<input type=""text"" size=""3"" value="""&iCurrentPage&""" onmouseover=""this.focus();this.select()"" id=""PGNumber"" />&nbsp;<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
    %>

  • 相关阅读:
    GIT使用方法
    结对-结对编项目贪吃蛇-设计文档
    结对-结对编项目贪吃蛇-开发环境搭建过程
    《团队-爬取豆瓣电影TOP250-需求分析》
    《团队-爬取豆瓣电影TOP250-成员简介及分工》
    结对-结对编项目贪吃蛇-需求分析
    20170906-构建之法:阅读问题
    20170906-构建之法:现代软件工程-阅读笔记
    团队名称:极限定理
    软件工程初识
  • 原文地址:https://www.cnblogs.com/MaxIE/p/720724.html
Copyright © 2020-2023  润新知