Page.class.php :

<?php
namespace Tools; 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;
} public 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 .= "&nbsp;&nbsp;<a href='{$this->uri}&page=1'>{$this->config["first"]}</a>&nbsp;&nbsp;";
} return $html;
} private function prev()
{
$html = "";
if ($this->page == 1) {
$html .= '';
} else {
$html .= "&nbsp;&nbsp;<a href='{$this->uri}&page=" . ($this->page - 1) . "'>{$this->config["prev"]}</a>&nbsp;&nbsp;";
} 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 .= "&nbsp;<a href='{$this->uri}&page={$page}'>{$page}</a>&nbsp;"; } $linkPage .= "&nbsp;{$this->page}&nbsp;"; for ($i = 1; $i <= $inum; $i++) {
$page = $this->page + $i;
if ($page <= $this->pageNum) {
$linkPage .= "&nbsp;<a href='{$this->uri}&page={$page}'>{$page}</a>&nbsp;";
} else {
break;
} } return $linkPage;
} private function next()
{
$html = "";
if ($this->page == $this->pageNum) {
$html .= '';
} else {
$html .= "&nbsp;&nbsp;<a href='{$this->uri}&page=" . ($this->page + 1) . "'>{$this->config["next"]}</a>&nbsp;&nbsp;";
} return $html;
} private function last()
{
$html = "";
if ($this->page == $this->pageNum) {
$html .= '';
} else {
$html .= "&nbsp;&nbsp;<a href='{$this->uri}&page=" . ($this->pageNum) . "'>{$this->config["last"]}</a>&nbsp;&nbsp;";
} return $html;
} private function goPage()
{
return '&nbsp;&nbsp;<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="GO" onclick="javascript:var page=(this.previousSibling.value>' . $this->pageNum . ')?' . $this->pageNum . ':this.previousSibling.value;location=\'' . $this->uri . '&page=\'+page+\'\'">&nbsp;&nbsp;';
}
public function fpage($display = array(0, 1, 2, 3, 4, 5, 6, 7, 8))
{
$html[0] = "&nbsp;&nbsp;共有<b>{$this->total}</b>{$this->config["header"]}&nbsp;&nbsp;";
$html[1] = "&nbsp;&nbsp;每页显示<b>" . ($this->end() - $this->start() + 1) . "</b>条,本页<b>{$this->start()}-{$this->end()}</b>条&nbsp;&nbsp;";
$html[2] = "&nbsp;&nbsp;<b>{$this->page}/{$this->pageNum}</b>页&nbsp;&nbsp;"; $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; } }

使用例子:

 $goods = D("Goods");

// 1)分页设置
$total = $goods->count(); // 总记录数
$listRows = 7; // 每页显示条数 // 2)实例化分页对象
$page = new \Tools\Page($total, $listRows); // 3)分页 sql 语句
$sql = "select * from sw_goods order by goods_id desc " . $page->limit;//limit 方法返回'limit xx,xx'
$info = $goods->query($sql); // 4)制作页码列表
$fpage = $page->fpage(array(3,4,5,6,7,8)); // 前面的统计信息不要 // 5)分配数组
$this->assign("info", $info);
$this->assign("pagelist", $fpage);
$this->display("showgoodslist");

 

---->>>

php : 自定义分页类的更多相关文章

  1. Django 自定义分页类

    分页类代码: class Page(object): ''' 自定义分页类 可以实现Django ORM数据的的分页展示 输出HTML代码: 使用说明: from utils import mypag ...

  2. thinkphp自定义分页类

    先来看下这个分页的样式,没写css,确实丑 什么时候写样式再来上传下css吧...... 就是多一个页面跳转功能 先把这个代码贴一下 <?php namespace Component; cla ...

  3. PHP24 自定义分页类

    分页类的定义 <?php /** * Class MyPage 分页类 * @package core */ class MyPage { private $totalCount; //数据表中 ...

  4. python 全栈开发,Day115(urlencode,批量操作,快速搜索,保留原搜索条件,自定义分页,拆分代码)

    今日内容前戏 静态字段和字段 先来看下面一段代码 class Foo: x = 1 # 类变量.静态字段.静态属性 def __init__(self): y = 6 # 实例变量.字段.对象属性 # ...

  5. python---django中自带分页类使用

    请先看在学习tornado时,写的自定义分页类:思路一致: python---自定义分页类 1.基础使用: 后台数据获取: from django.core.paginator import Pagi ...

  6. [ Laravel 5.6 文档 ]laravel数据库操作分页(自定义分页实现和自定义分页样式)

    简介 在其他框架中,分页可能是件非常痛苦的事,Laravel 让这件事变得简单.易于上手.Laravel 的分页器与查询构建器和 Eloquent ORM 集成在一起,并开箱提供方便的.易于使用的.基 ...

  7. 好用的ASP.NET 分页类 简单好用 支持 AJAX 自定义文字

    在做网站没用 JS UI控件时 很实用 用法: var ps=new PageString(); /*可选参数*/ ps.SetIsEnglish = true;// 是否是英文 (默认:false) ...

  8. TP5 分页类,自定义样式

    结合X-admin 后台框架 在做项目,为了保持分页风格的一致,所以需要自定义 一个分页类. 一.在项目的 extend 目录,创建 cus 目录 二.创建 Page 分页类,代码如下 <?ph ...

  9. ThinkPHP3验证码、文件上传、缩略图、分页(自定义工具类、session和cookie)

    验证码 TP框架中自带了验证码类 位置:Think/verify.class.php 在LoginController控制器中创建生存验证码的方法 login.html登陆模板中 在LoginCont ...

随机推荐

  1. AFNETWorking 不支持中文URL请求

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 14.0px Menlo; color: #000000; min-height: 16.0px } p.p ...

  2. python web前端

    概述 HTML是英文Hyper Text Mark-up Language(超文本标记语言)的缩写,他是一种制作万维网页面标准语言(标记).相当于定义统一的一套规则,大家都来遵守他,这样就可以让浏览器 ...

  3. c 头文件<ctype.h>(二)

    测试<ctype.h>函数 #include <stdio.h> #include <ctype.h> int main(){ ; ; i < ; ++i){ ...

  4. windows2003 iis php 配置后无法执行php页面

    1.问题:可以访问静态页面,无法访问php脚本页面,显示404 解决:

  5. PeopleSoft Home Subdirectories

    PeopleSoft Home Subdirectories appserv — home to the Application Server and Process Scheduler Server ...

  6. Python Thread related

    1.Thread.join([timeout]) Wait until the thread terminates. This blocks the calling thread until the ...

  7. Java开发环境的配置与Hello World

    一.Java开发需要做的准备 Java程序的执行过程是首先由Java编译器将以.java为后缀的Java源文件编译成.class字节码文件.然后字节码文件便可以由JVM虚拟机进行加载并执行. 在初学J ...

  8. 在Excel表格中输入一大段文字

    1.有时为了注释的需要,在excel中需要输入一大段文字,这时候可以使用—视图-工具-绘图,然后选择下面的文本框,即可自定义文本框大小,如需要文本框和表格边框完全重合,在鼠标画文本框时按住 Alt键.

  9. percona server 二进制安装下编译tpcc-mysql的坑

    出于习惯,percona server的部署都是通过二进制包自动化安装,结果遇到一个硕大无比的坑,编译TPCC-MySQL时出现警告 10:49:36 root@DB-Master:~/tpcc-my ...

  10. linux 中更改用户权限和用户组的命令chmod,chgrp实例

    linux 中更改用户权限和用户组的命令实例; 增加权限给当前用户 chmod +wx filename chmod -R 777 /upload 用户组 chgrp -R foldname zdz ...