热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

asp分页的一个类

asp分页的一个类
asp分页的一个类 
在50,000条记录下测试过,速度比ado的那个要快多了 

<%

'************************************************************************************
'具体用法
Dim strDbPath
Dim connstr
Dim mp
Set mp = New MyPage
strDbPath = "fenye/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
set rs = mp.Execute("select * from table1",conn,29)
while not rs.eof
    response.write rs("aaaa")&"
"
    rs.MoveNext
wend
mp.pageDispaly()
'************************************************************************************
Class MyPage
    private MyPage_Conn,MyPage_StrSql,MyPage_TotalStrSql,MyPage_RS,MyPage_TotalRS
    private MyPage_PageSize
    private MyPage_PageAbsolute,MyPage_PageTotal,MyPage_RecordTotal
    private MyPage_Url
    public property let conn(strConn)
    set MyPage_Conn = strConn
    end property

    public property let PageSize(intPageSize)
        MyPage_PageSize = Cint(intPageSize)
    end property

    public function PageExecute(strSql)
        MyPage_PageAbsolute = MyPage_PageAbsoluteRequest()
        MyPage_TotalStrSql = FormatMyPage_TotalStrSql(strSql) 
        set MyPage_TotalRS = MyPage_Conn.execute(MyPage_TotalStrSql)
        MyPage_RecordTotal = MyPage_TotalRS("total")
        MyPage_PageTotal = Cint(MyPage_RecordTotal/MyPage_PageSize)
        MyPage_StrSql = FormatMyPage_StrSql(strSql)
        set MyPage_RS = MyPage_Conn.execute(MyPage_StrSql)
        dim i
        i = 0 
        while not MyPage_RS.eof and  i<(MyPage_PageAbsolute-1)*MyPage_PageSize
            i = i + 1
            MyPage_RS.MoveNext
        wend
        set PageExecute = MyPage_RS 
    end function

    public function Execute(strSql,strConn,intPageSize)
        conn = strConn
        PageSize = intPageSize
        set Execute = PageExecute(strSql)
    end function

    public function pageDispaly()
        MyPage_Url = ReadMyPage_Url
        firstPageTag = "9"  '|<<
        LastPageTag = ":"  '>>|
        previewPageTag = "7"  '<<
        nextPageTag = "8"  '>>
        dim strAnd
        if instr(MyPage_Url,"?")=0 then
            strAnd = "?"
        else
            strAnd = "&"
        end if
        response.write "        response.write ""
        response.write ""
        response.write  "页次:"&MyPage_PageAbsolute&"/"&MyPage_PageTotal&"页 "
        response.write  "主题数:"&MyPage_RecordTotal
        response.write ""
        response.write ""
        response.write  "分页:"
        if MyPage_PageAbsolute>10 then
            response.write  ""&firstPageTag&""
            response.write  ""&previewPageTag&""
        else
            response.write  firstPageTag
            response.write  previewPageTag
        end if
        response.write " "
        dim CurrentStartPage,i
        i = 1
        CurrentStartPage=(Cint(MyPage_PageAbsolute)\10)*10+1
        if Cint(MyPage_PageAbsolute) mod 10=0 then
            CurrentStartPage = CurrentStartPage - 10
        end if
        while i<11 and CurrentStartPage            if CurrentStartPage < 10 then
                FormatCurrentStartPage = "0" & CurrentStartPage
            else
                FormatCurrentStartPage = CurrentStartPage
            end if
            response.write  ""&FormatCurrentStartPage&" "
            i = i + 1
            CurrentStartPage = CurrentStartPage + 1
        wend
        if MyPage_PageAbsolute<(MyPage_PageTotal-10) then
            response.write  ""&nextPageTag&""
            response.write  ""&LastPageTag&""
        else
            response.write  nextPageTag
            response.write  LastPageTag
        end if
        response.write  ""
        response.write ""
        response.write "" 
        response.write ""
    end function

    public function GetPageNo()
        GetPageNo = cint(MyPage_PageAbsolute)
    end function

    public function GetPageCount()
        GetPageCount = cint(MyPage_PageTotal)
    end function

    public function GetPageNoName()
        GetPageNoName = "MyPage_PageNo"
    end function

    public function GetPageSize()
        GetPageSize = MyPage_PageSize
    end function

    public function GetRecordTotal()
        GetRecordTotal = MyPage_RecordTotal
    end function

    

    private function FormatMyPage_TotalStrSql(strSql)
        FormatMyPage_TotalStrSql = "select count(*) as total "
        FormatMyPage_TotalStrSql = FormatMyPage_TotalStrSql & Mid(strSql,instr(strSql,"from"))
        FormatMyPage_TotalStrSql = Mid(FormatMyPage_TotalStrSql,1,instr(FormatMyPage_TotalStrSql&"order by","order by")-1)
    end function

    private function FormatMyPage_StrSql(strSql)
        FormatMyPage_StrSql = replace(strSql,"select","select top "&(MyPage_PageAbsolute*Cint(MyPage_PageSize)))
    end function

    private function MyPage_PageAbsoluteRequest()
        if request("MyPage_PageNo")="" then 
            MyPage_PageAbsoluteRequest = 1
        else
            if IsNumeric(request("MyPage_PageNo")) then
                MyPage_PageAbsoluteRequest = request("MyPage_PageNo")
            else
                MyPage_PageAbsoluteRequest = 1
            end if
        end if
    end function

    private function ReadMyPage_Url()
        ReadMyPage_Url = Request.ServerVariables("URL")
        if Request.QueryString<>"" then
            ReadMyPage_Url = ReadMyPage_Url & "?" & Request.QueryString 
        end if
        set re = new RegExp
        re.Pattern = "[&|?]MyPage_PageNo=\d+?"
        re.IgnoreCase = true
        re.multiLine = true
        re.global = true
        Set Matches = re.Execute(ReadMyPage_Url) 
        For Each Match in Matches  
            tmpMatch = Match.Value
            ReadMyPage_Url = replace(ReadMyPage_Url,tmpMatch,"")
        next
    end function
end Class

%> 



推荐阅读
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 本文介绍了在SQL中查询分组后每组行数的统计方法。通过使用count()函数和GROUP BY子句可以统计每组的行数,但是如何统计所有组的行数呢?本文提供了一种实现方法,并给出了相应的SQL查询语句。 ... [详细]
  • 在数据分析工作中,我们通常会遇到这样的问题,一个业务部门由若干业务组构成,需要筛选出每个业务组里业绩前N名的业务员。这其实是一个分组排序的 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • Oracle Database 10g许可授予信息及高级功能详解
    本文介绍了Oracle Database 10g许可授予信息及其中的高级功能,包括数据库优化数据包、SQL访问指导、SQL优化指导、SQL优化集和重组对象。同时提供了详细说明,指导用户在Oracle Database 10g中如何使用这些功能。 ... [详细]
  • 本文介绍了adg架构设置在企业数据治理中的应用。随着信息技术的发展,企业IT系统的快速发展使得数据成为企业业务增长的新动力,但同时也带来了数据冗余、数据难发现、效率低下、资源消耗等问题。本文讨论了企业面临的几类尖锐问题,并提出了解决方案,包括确保库表结构与系统测试版本一致、避免数据冗余、快速定位问题等。此外,本文还探讨了adg架构在大版本升级、上云服务和微服务治理方面的应用。通过本文的介绍,读者可以了解到adg架构设置的重要性及其在企业数据治理中的应用。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了使用postman进行接口测试的方法,以测试用户管理模块为例。首先需要下载并安装postman,然后创建基本的请求并填写用户名密码进行登录测试。接下来可以进行用户查询和新增的测试。在新增时,可以进行异常测试,包括用户名超长和输入特殊字符的情况。通过测试发现后台没有对参数长度和特殊字符进行检查和过滤。 ... [详细]
  • 本文详细介绍了MysqlDump和mysqldump进行全库备份的相关知识,包括备份命令的使用方法、my.cnf配置文件的设置、binlog日志的位置指定、增量恢复的方式以及适用于innodb引擎和myisam引擎的备份方法。对于需要进行数据库备份的用户来说,本文提供了一些有价值的参考内容。 ... [详细]
  • 使用Ubuntu中的Python获取浏览器历史记录原文: ... [详细]
  • 本文由编程笔记小编整理,介绍了PHP中的MySQL函数库及其常用函数,包括mysql_connect、mysql_error、mysql_select_db、mysql_query、mysql_affected_row、mysql_close等。希望对读者有一定的参考价值。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • Java String与StringBuffer的区别及其应用场景
    本文主要介绍了Java中String和StringBuffer的区别,String是不可变的,而StringBuffer是可变的。StringBuffer在进行字符串处理时不生成新的对象,内存使用上要优于String类。因此,在需要频繁对字符串进行修改的情况下,使用StringBuffer更加适合。同时,文章还介绍了String和StringBuffer的应用场景。 ... [详细]
  • Oracle分析函数first_value()和last_value()的用法及原理
    本文介绍了Oracle分析函数first_value()和last_value()的用法和原理,以及在查询销售记录日期和部门中的应用。通过示例和解释,详细说明了first_value()和last_value()的功能和不同之处。同时,对于last_value()的结果出现不一样的情况进行了解释,并提供了理解last_value()默认统计范围的方法。该文对于使用Oracle分析函数的开发人员和数据库管理员具有参考价值。 ... [详细]
author-avatar
默一
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有