php分页类

Eddy 发布于2013-3-11 23:14:48 分类: 技术心得 已浏览loading 网友评论1条 我要评论

[FONT-SIZE=3]

自己写了个分页类,表现层基于bootstrap。

pagination.class.php

[CODE=php]

/**
* 分页类,表现层基于bootstrap
*
* @author Eddy
* */
class pagination {

private $pageSize; // 每页显示记录数
private $totalCount; // 总记录数
private $pageUrl; // 页面链接
private $pageNavNum; // 导航条条目数
public $pageNum; // 总页数
public $curPageNum; // 当前页面
public $showGoto; // 是否显示跳转连接
public $position; // 分页导航位置 right center left
public $showTotal; // 是否显示总页数

// 构造函数

public function __construct($totalCount, $pageSize, $pageUrl, $pageNavNum, $showGoto = false, $showTotal = false, $position = 'right') {
$this->totalCount = $totalCount;
$this->pageSize = $pageSize;
$this->pageUrl = $pageUrl;
$this->pageNavNum = $pageNavNum > 3 ? $pageNavNum : 3;
$this->pageNum = ceil($totalCount / $pageSize);
$this->position = $position;
$this->showGoto = $showGoto;
$this->showTotal = $showTotal;
}

// 获取分页导航链接数组
private function getNavUrlArr() {
$navUrl = array();
if ($this->pageNum > $this->pageNavNum) {
if ($this->pageNum - $this->curPageNum < $this->pageNavNum) {
$start = $this->pageNum - $this->pageNavNum + 1;
} else {
$start = $this->curPageNum;
}

for ($i = $start; $i < min($this->pageNavNum + $this->curPageNum, $this->pageNum + 1); $i++) {
if ($this->curPageNum == $i) {
$navUrl [] = '
  • ' . $i . '
  • ';
    } else {
    $navUrl [] = '
  • ' . $i . '
  • ';
    }
    }
    } else {
    for ($i = 0; $i < $this->pageNum; $i++) {
    if ($this->curPageNum == $i + 1) {
    $navUrl [] = '
  • ' . ($i + 1) . '
  • ';
    } else {
    $navUrl [] = '
  • ' . ($i + 1) . '
  • ';
    }
    }
    }

    return $navUrl;
    }

    // 生成分页导航条
    public function generatePageNav() {
    $navStr = '';
    $midStr = '';
    if ($this->position == 'right') {
    $navStr .= '

    关于 php分页  的相关文章

    1. 发表于2013-3-24 18:57:48

      刚好新建了织梦网站,碰到了这个问题,想PHP分页,找了很久都没找到方法,想不到在这里可以找到了

    记住我的信息,下次不用再输入 欢迎给Eddy Blog留言