MySQL数据库分页模型(Pagination.php)_MySQL数据库_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

MySQL数据库分页模型(Pagination.php)

作者:黑客防线网安MYSQL维护基地 来源:黑客防线网安MYSQL维护基地 浏览次数:0

本篇关键词:模型this->pageNo
黑客防线网安网讯:class Pagination {        var $pageSize;        //页大小        var $pageNo;                //当前页码        var $rowCount;        //记录总数        var $pageCount;        //总...

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 < $this->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<1 || $pageNo<1 ) return false;

                //查询
                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( $read<$this->pageSize && $row=@mysql_fetch_array($rst) ){
                                $this->records[$this->currentPageSize++] = $dataMaker($row);
                                $read++;
                        }
                }
                else{
                        return false;
                }

                return true;
        }
};
?>

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-8218-1.html
网站维护教程更新时间:2012-03-20 04:50:25  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer