当前位置:编程学习 > php >>

PHP 分页类

下面是我自己的分页类,可适当的修改 
[php] 
<?php   
/**  
 * @name Pager's class  
 * @author Refer  
 * @copyright www.phpcq.com  
 * @version Alpha 1.0  
 * @todo 下拉菜单分页---From表单传值...可以根据自己的情况(采用GET传值)  
 *  
 */   
class Pager{   
    /**  
     * startRow  
     *  
     * @var Int  
     */   
    public $startRow;   
    /**  
     * 页面的总数  
     *  
     * @var Int  
     */   
    public $pageTotal;   
    /**  
     *翻页值  
     *  
     * @var Int  
     */   
    public $offset;   
    /**  
     * 每页所显示记录数  
     *  
     * @var Int  
     */   
    public $pageSize;   
    /**  
     * get参数  
     *  
     * @var Int  
     */   
    public $get;   
    /**  
     * post参数  
     *  
     * @var Int  
     */   
    public $post;   
    /**  
     * 构造函数--初始化翻页类 (PS:^_^不错的php开发学习交流群:256271784,验证:gole,有兴趣的话可以加入进来一起讨论) 
     *  
     * @param Int $total  
     * @param Int $pageSize  
     */   
    public function __construct($total,$pageSize){   
        $this->get = (int)$_GET['startRow'];   
        $this->post = (int)$_POST['pageNums'];   
        $this->pageSize = $pageSize;   
        $this->pageTotal = ceil($total / $pageSize);   
        switch ($_GET['method']){   
            default:   
                $this->startRow = 1;   
                $this->offset = 0;   
            break;   
            case 'first':   
                $this->first();   
            break;       
            case 'previous':   
                $this->previous();   
            break;       
            case 'next':   
                $this->next();   
            break;       
            case 'last':   
                $this->last();   
            break;       
        }   
    }    
    /**  
     * 首页方法  
     *  
     */   
    public function first(){   
        $this->startRow = 1;   
        $this->offset = ($this->startRow - 1) * $this->pageSize;  
    }   
    /**  
     * 上一页方法  
     *  
     */   
    public function previous(){   
        $this->startRow = $this->get - 1;   
        if ($this->startRow < 1) {   
            $this->startRow = 1;   
        }   
        $this->offset = ($this->startRow - 1) * $this->pageSize;  
    }   
    /**  
     * 下一页方法  
     *  
     */   
    public function next(){   
        $this->startRow = $this->get + 1;   
        if ($this->startRow > $this->pageTotal) {   
            $this->startRow = $this->pageTotal;   
        }   
        $this->offset = ($this->startRow - 1) * $this->pageSize;  
    }   
    /**  
     * 最后页方法  
     *  
     */   
    public function last(){   
        $this->startRow = $this->pageTotal;   
        $this->offset = ($this->startRow - 1) * $this->pageSize;  
    }   
    /**  
     * 下拉菜单翻页  
     *  
     * @return Int  
     */   
    public function numPages(){   
        if ($this->post) {   
            $pageNums = "<option>$this->post</option>";   
            $this->startRow = $this->post;   
            $this->offset = ($this->post - 1) * $this->pageSize;  
        }   
        for ($i = 1; $i <= $this->pageTotal;$i++){   
            if ($i != $thi
补充:Web开发 , php ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,