page.class.php

<?php
namespace Component;
class Page { private $total; //数据表中总记录数
private $listRows; //每页显示行数
private $limit;
private $uri;
private $pageNum; //页数
private $config = array('header' => "个记录", "prev" => "上一页", "next" => "下一页", "first" => "首 页", "last" => "尾 页");
private $listNum = 8; /*
* $total
* $listRows
*/ public function __construct($total, $listRows = 10, $pa = "") {
$this->total = $total;
$this->listRows = $listRows;
$this->uri = $this->getUri($pa);
$this->page = !empty($_GET["page"]) ? $_GET["page"] : 1;
$this->pageNum = ceil($this->total / $this->listRows);
$this->limit = $this->setLimit();
} private function setLimit() {
return "Limit " . ($this->page - 1) * $this->listRows . ", {$this->listRows}";
} private function getUri($pa) {
$url = $_SERVER["REQUEST_URI"] . (strpos($_SERVER["REQUEST_URI"], '?') ? '' : "?") . $pa;
$parse = parse_url($url); if (isset($parse["query"])) {
parse_str($parse['query'], $params);
unset($params["page"]);
$url = $parse['path'] . '?' . http_build_query($params);
} return $url;
} function __get($args) {
if ($args == "limit")
return $this->limit;
else
return null;
} private function start() {
if ($this->total == 0)
return 0;
else
return ($this->page - 1) * $this->listRows + 1;
} private function end() {
return min($this->page * $this->listRows, $this->total);
} private function first() {
$html = "";
if ($this->page == 1)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=1'>{$this->config["first"]}</a>  "; return $html;
} private function prev() {
$html = "";
if ($this->page == 1)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=" . ($this->page - 1) . "'>{$this->config["prev"]}</a>  "; return $html;
} private function pageList() {
$linkPage = ""; $inum = floor($this->listNum / 2); for ($i = $inum; $i >= 1; $i--) {
$page = $this->page - $i; if ($page < 1)
continue; $linkPage .= " <a href='{$this->uri}&page={$page}'>{$page}</a> ";
} $linkPage .= " {$this->page} "; for ($i = 1; $i <= $inum; $i++) {
$page = $this->page + $i;
if ($page <= $this->pageNum)
$linkPage .= " <a href='{$this->uri}&page={$page}'>{$page}</a> ";
else
break;
} return $linkPage;
} private function next() {
$html = "";
if ($this->page == $this->pageNum)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=" . ($this->page + 1) . "'>{$this->config["next"]}</a>  "; return $html;
} private function last() {
$html = "";
if ($this->page == $this->pageNum)
$html .= '';
else
$html .= "  <a href='{$this->uri}&page=" . ($this->pageNum) . "'>{$this->config["last"]}</a>  "; return $html;
} private function goPage() {
return '  <input type="text" onkeydown="javascript:if(event.keyCode==13){var page=(this.value>' . $this->pageNum . ')?' . $this->pageNum . ':this.value;location=\'' . $this->uri . '&page=\'+page+\'\'}" value="' . $this->page . '" style="width:25px"><input type="button" value="跳转" onclick="javascript:var page=(this.previousSibling.value>' . $this->pageNum . ')?' . $this->pageNum . ':this.previousSibling.value;location=\'' . $this->uri . '&page=\'+page+\'\'">  ';
} function fpage($display = array(0, 1, 2, 3, 4, 5, 6, 7, 8)) {
$html[0] = "  共有<b>{$this->total}</b>{$this->config["header"]}  ";
// $html[1] = "  每页显示<b>" . ($this->end() - $this->start() + 1) . "</b>条,本页<b>{$this->start()}-{$this->end()}</b>条  ";
$html[2] = "  <b>{$this->page}/{$this->pageNum}</b>页  "; $html[3] = $this->first();
$html[4] = $this->prev();
$html[5] = $this->pageList();
$html[6] = $this->next();
$html[7] = $this->last();
$html[8] = $this->goPage();
$fpage = '';
foreach ($display as $index) {
$fpage .= $html[$index];
} return $fpage;
} }

  

控制器调用方法:

function serverlist(){
$goods = D(ops_gz);
//总页数计算
$count = $goods->count();
$per = 10;
//实例化分页类
$page = new \Component\page($count,$per);
//拼装sql语句
$sql = "select * from ops_gz ".$page->limit;
$info = $goods->query($sql);
//获取页码列表
$pagelist = $page->fpage();
$this->assign(info,$info);
$this->assign(pagelist,$pagelist);
$this->display();
}

view

php分页类的实现与调用 (自我摘记)的更多相关文章

  1. php分页类的二种调用方法(转载)

    php分页类的二种调用方法 原文地址:http://www.xfcodes.com/php/fenye/25584.htm 导读:php分页类的二种调用用法,ajax调用php分页类,非ajax方式调 ...

  2. php分页类 可直接调用

    <?php /** * 分页类 * @author xyy * 调用分页实例 $subPages=new SubPages(数据总条数);//实例化分页类 * //$subPages->s ...

  3. php实现的分页类

    php分页类文件: <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 pr ...

  4. asp.net的快捷实用分页类

    KeleyiPager分页类,可以于对列表页进行分页浏览,代码是从HoverTreeCMS项目中COPY的,感觉很不错,使用简单方便,但是功能强大. 在线体验效果:http://cms.hovertr ...

  5. PHPCMS V9 分页类的修改教程

    首先,打开 phpcms\libs\functions\global.func.php 这个文件,找到文件第622行的分页函数,复制一下,粘贴到默认分页函数的下面,重新命名后保存.(笔者在此命名为:p ...

  6. php 简单分页类

    /**  file: page.class.php   完美分页类 Page  */ class Page {  private $total;          //数据表中总记录数  privat ...

  7. php部分---一个分页类、用法

    1.分页类 <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 privat ...

  8. webpy分页类 + 上传类

    webpy没有分页类.按照php的思路.自己编了一个.数据库用的是sqlite. class Page(object): '''分页类''' def __init__(self,page_size,d ...

  9. php分页类代码带分页样式效果(转)

    php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...

随机推荐

  1. POJ 3528--Ultimate Weapon(三维凸包)

    Ultimate Weapon Time Limit: 2000MS   Memory Limit: 131072K Total Submissions: 2430   Accepted: 1173 ...

  2. HDU Ellipse(simpson积分)

    Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  3. chromium之dynamic_annotations

    看看介绍 // This file defines dynamic annotations for use with dynamic analysis // tool such as valgrind ...

  4. ABAP术语-SAPNET

    SAPNET 原文:http://www.cnblogs.com/qiangsheng/archive/2008/03/17/1109823.html SAPNet is the intranet p ...

  5. [读书笔记] Spring MVC 学习指南 -- 第一章

    控制反转(Inversion of Control, IoC)/ 依赖注入: 比如说,类A依赖于类B,A需要调用B的某一个方法,那么在调用之前,类A必须先获得B的一个示例引用. 通常我们可以在A中写代 ...

  6. Oracle条件判断列数量非where

    sum(case when typename='测试' then 1 else 0 end)

  7. HTML5之特效

    2D转换 在二维的平面上做一些变化,使用transform属性 1. 2D转换之移动(translate) 案例: div{ width: 200px; height: 200px; backgrou ...

  8. [翻译]Hystrix wiki–Home

    注:本文并非是精确的文档翻译,而是根据自己理解的整理,有些内容可能由于理解偏差翻译有误,有些内容由于是显而易见的,并没有翻译,而是略去了.本文更多是学习过程的产出,请尽量参考原官方文档. 什么是Hys ...

  9. Flask之Flask实例有哪些参数

    常用的参数应用实例 from flask import Flask, render_template, url_for, session, request, redirect app = Flask( ...

  10. api帮助文档的制作

    在java开发中,往往需要用到别人写的类或是自己写的类被别人拿去用. 而使用类的过程中,类中的方法对使用者而言并不完全透明,这个时候帮助文档可以让我们清楚的了解这个类中的方法该如何调用. 下面简述一下 ...