首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 冲浪宝典 > 网络资源 > MySQL分页模型(Pagination.php)
【标  题】:MySQL分页模型(Pagination.php)
【关键字】:SQL,in,io,分页,at,php,agi,on,My,MySQL,MySQL,Pagination,php
【来  源】:网络

MySQL分页模型(Pagination.php)


*/

class Pagination {
        var $pageSize;        //页大小
        var $pageNo;                //当前页码
        var $rowCount;        //记录总数
        var $pageCount;        //总页数
        var $records;                //当前页记录
        var $currentPageSize;        //当前页记录总数
        var $currentPageStartNo;     //当前页开始记录号

        //判断是否有下一页
        function hasNextPage() {
                return $this->pageNo < $this->pageCount;
        }
        //取得下一页页码
        function getNextPageNo() {
                return $this->pageNo + 1;
        }

        //判断是否有上一页
        function hasPriorPage() {
                return $this->pageNo > 1;
        }
        //取得上一页页码
        function getPriorPageNo() {
                return $this->pageNo - 1;
        }

        //判断是否第一页
        function isFirstPage(){
                return $this->pageNo == 1 || $this->pageCount==0;
        }

        //判断是否最后一页
        function isLastPage(){
                return $this->pageNo == $this->pageCount || $this->pageCount==0;
        }

        //装载某一页数据,成功则返回true,失败则返回false
        //        dataMaker是一个函数名,用于将一条记录转换为一个对象
        //        有一个参数为当前记录所有字段的值(一个以数字或字段名为索引的数组)
        function load($con, $sql, $dataMaker, $pageSize, $pageNo){
                //页大小和当前页码必须>=1
                if( $pageSize<1 || $pageNo<1 ) return false;

                //查询
                if( $rst = @mysql_query($sql, $con) ){
                        $this->pageSize = $pageSize;
                        $this->pageNo = $pageNo;

                        $this->rowCount = @mysql_num_rows($rst);
                        $this->pageCount = (int)(($this->rowCount + $this->pageSize - 1) / $this->pageSize);
                        $this->records = array();

                        //将光标移动到指定页的第一条记录前
                        $this->currentPageStartNo = ($this->pageNo - 1) * $this->pageSize + 1;
                        $firstRowNo = $this->currentPageStartNo;
                        while( --$firstRowNo>0 && @mysql_fetch_array($rst) );

                        //取出指定页的数据
                        $read = 0;
                        $this->currentPageSize = 0;
                        while( $read<$this->pageSize && $row=@mysql_fetch_array($rst) ){
                                $this->records[$this->currentPageSize++] = $dataMaker($row);
                                $read++;
                        }
                }
                else{
                        return false;
                }

                return true;
        }
};
?>

使用Delphi6的DBExpress组件连接远程的Mysql数据库:【上一篇】
学习MySQL多表操作和备份处理:【下一篇】
【相关文章】
  • 使用Delphi6的DBExpress组件连接远程的Mysql数据库
  • 用perl访问mysql数据库
  • 用javabean来实现MySQL的分页显示
  • sql交叉查询
  • SQL 语法参考
  • SQL语法速成
  • MYSQL数据库的查询优化技术
  • sql note
  • mysql max版本如何修改默认字符集
  • 破解本地的mysql用户名和密码
  • 【随机文章】
  • “Saturniid(天蚕蛾)”开发进度
  • Oracle SQL 内置函数大全
  • 如何为live.com编写并添加自己的Gadget (一)
  • 城域網出口調整思路
  • [转载ibm]解析 Linux 中的 VFS 文件系统机制
  • RSS Utilities: A Tutorial
  • 没有Ghost照样克隆硬盘
  • 读易[5]·做鸡头还是凤尾(小过卦)
  • 《LoadRunner 没有告诉你的》之三——理发店模型
  • How hide standard button when output with alv in abap.
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 软讯网络 All Rigths Reserved.