php分页类的实现与调用 (自我摘记)
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分页类的实现与调用 (自我摘记)的更多相关文章
- php分页类的二种调用方法(转载)
php分页类的二种调用方法 原文地址:http://www.xfcodes.com/php/fenye/25584.htm 导读:php分页类的二种调用用法,ajax调用php分页类,非ajax方式调 ...
- php分页类 可直接调用
<?php /** * 分页类 * @author xyy * 调用分页实例 $subPages=new SubPages(数据总条数);//实例化分页类 * //$subPages->s ...
- php实现的分页类
php分页类文件: <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 pr ...
- asp.net的快捷实用分页类
KeleyiPager分页类,可以于对列表页进行分页浏览,代码是从HoverTreeCMS项目中COPY的,感觉很不错,使用简单方便,但是功能强大. 在线体验效果:http://cms.hovertr ...
- PHPCMS V9 分页类的修改教程
首先,打开 phpcms\libs\functions\global.func.php 这个文件,找到文件第622行的分页函数,复制一下,粘贴到默认分页函数的下面,重新命名后保存.(笔者在此命名为:p ...
- php 简单分页类
/** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 privat ...
- php部分---一个分页类、用法
1.分页类 <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 privat ...
- webpy分页类 + 上传类
webpy没有分页类.按照php的思路.自己编了一个.数据库用的是sqlite. class Page(object): '''分页类''' def __init__(self,page_size,d ...
- php分页类代码带分页样式效果(转)
php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...
随机推荐
- js检测是否可以访问公网服务器
wifi认证开发过程所用到的,源码如下: 注:检测AC是否放行成功,是否可以访问公网阿里云服务器 功能调用: checkNet().then(function(res) { if(res) { //连 ...
- PHP程序员面试中经常被提问的问题【转载】
1. Include 与 require的区别,require和require_once的效率哪个高? Php在遇到include时就解释一次,如果页面中出现10次include,php就解释10次, ...
- 05JavaScript语句
1.JavaScript 语句 JavaScript 语句是发给浏览器的命令. 这些命令的作用是告诉浏览器要做的事情. 2.分号 ; 分号用于分隔 JavaScript 语句. 通常我们在每条可执行的 ...
- Hibernate 事务不回滚
问题: 这几天在做开发时,发现事务不回滚了,Service是用AOP加的事务,数据库是MySql, 表全部是InnoDB: 方法回滚是采用spring的手动回滚: ...
- 闰年相关的问题v3.0——计算有多少闰年
# include<stdio.h>int main(){ int a,b,i; int sum = 0; printf("Input your birth year:" ...
- linux 通过 openconnect 来连接学校内网
参考 http://xingda1989.iteye.com/blog/1969908 https://blog.csdn.net/edin_blackpoint/article/details/70 ...
- golang 并发执行函数func类型slice
golang的slice支持func.使用func slice要注意func要完整描述入参出参. 如果需要执行一系列类型相同(入参出参格式相同)的函数,可以动态添加到一个slice里面.range s ...
- 使用idea上传项目到gitHub
上传项目到gitHub 创建好后开始提交本地项目代码如图: 选中VCS选中图中的按钮如图所示: 然后再选中Src点中add按钮如图所示: 然后点中commit Directory后 打开终端进行项目根 ...
- git配置config记住密码
设置记住密码(默认15分钟): git config --global credential.helper cache如果想自己设置时间,可以这样做: git config credential.he ...
- 北京Uber优步司机奖励政策(1月9日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...