Home  >  Article  >  Database  >  MySQL分页模型(Pagination.php)_MySQL

MySQL分页模型(Pagination.php)_MySQL

WBOY
WBOYOriginal
2016-06-01 13:55:311288browse

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

        //判断是否有电脑教程之家 http://www.pcppc.cn
        function hasNextPage() {
                return $this->pageNo pageCount;
        }
        //取得电脑教程之家 http://www.pcppc.cn页码
        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

                //查询
                if( $rst = @mysql_que


MySQL教程是:MySQL分页模型(Pagination.php)。ry($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( $readpageSize && $row=@mysql_fetch_array($rst) ){
                                $this->records[$this->currentPageSize++] = $dataMaker($row);
                                $read++;
                        }
                }
                else{
                        return false;
                }

                return true;
        }
};
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn