专注于高品质PHP技术等信息服务于一体 [STIEMAP] [RSS]

百度提供的广告:
PHP
当前位置:首页 > 技术文档 > PHP >  > 
php 分页基类源码

<?php
/**
 *分页
 */
class page  {
    public $all_count;
    public $all_page;
    public $page_size;
    public $now_page;
    public $page_link;

    public function init($count)
    {
        $this->page_size = 10;
        $this->all_count = $count;
        $this->all_page = floor(($this->all_count-1)/$this->page_size)+1;
        //参数
        $url  =  $_SERVER['QUERY_STRING'];
        $flag = strpos($url,'&');
        $url = (0<$flag) ? substr($url,0,$flag) : $url;
        //分页链接
        $this->page_link = '共'.$this->all_page.'页';
        $this->page_link .= '    ';
        $this->page_link .= "<a href='?$url&n=0'>首页</a>";
        $this->page_link .= '    ';
        if(0<$this->now_page)
        {
            $this->page_link .= "<a href='?$url&n=".($this->now_page-1)."'>《上一页</a>";
        }
        else
        {
            $this->page_link .= '《上一页';
        }
        $this->page_link .= '    ';
        if($this->all_page>$this->now_page)
        {
            $this->page_link .= "<a href='?$url&n=".($this->now_page+1)."'>下一页》</a>";
        }
        else
        {
            $this->page_link .= '下一页》';
        }
        $this->page_link .= '    ';
        $this->page_link .= "<a href='?$url&n=".$this->all_page."'>最后一页</a>";
       
    }
}


?>