zoukankan      html  css  js  c++  java
  • php的基础分页类

    class Page
    
    {
    
    public $limit;	//存储limit条件
    
    public $allPage;	//存储总页数
    
    public $current;	//存储当前页
    
    public $total;	//存储总条数
    
    public function __construct($total, $num = 5)
    
    {
    
    //计算总页数
    
    $this->allPage = ceil($total/$num);
    
    //处理当前页
    
    $this->current();
    
    //3,3  6,3
    
    $this->limit = (($this->current-1)*$num).','.$num;
    
    $this->total = $total;
    
    }
    
    protected function current()
    
    {
    
    $p = isset($_GET['p']) ? $_GET['p'] : 1;
    
    // $p = max(1, $p);	//最小不能小于1
    
    // $p = min($p, $this->allPage);//最大不能超过总页数
    
    if ($p < 1) $p = 1;
    
    if ($p > $this->allPage) $p = $this->allPage;
    
    $this->current = (int)$p;
    
    }
    
    public function show()
    
    {
    
    $first = $end = $pre = $next = $_GET;//处理上一页$pre['p'] = $this->current - 1;
    
    $preStr = http_build_query($pre);
    
    //处理下一页$next['p'] = $this->current + 1;$nextStr = http_build_query($next);
    
    //处理首页$first['p'] = 1;
    
    $firstStr = http_build_query($first);
    
    //处理尾页$end['p'] = $this->allPage;
    
    $endStr = http_build_query($end);
    
    $str = "共{$this->total}条数据 第{$this->current}/{$this->allPage}页 | ";
    
    $str .= "首页| ";$str .= "上一页| ";$str .= "下一页| ";$str .= "尾页";
    
    return $str;
    
        }
    
    }

  • 相关阅读:
    ubuntu安装pgAdmin 4
    python 读取文件
    byobu copy
    vim快捷键汇总
    python 停止线程
    python执行外部命令并获取输出
    gevent mysql
    python类型转换
    量化交易
    Java集合:HashMap底层实现和原理(源码解析)
  • 原文地址:https://www.cnblogs.com/hoewang/p/10257291.html
Copyright © 2011-2022 走看看