php+mysql分页类的入门实例
php+mysql分页类的简单代码
- 时间:2016-02-25 06:16:26来源:网络
一、php分页类代码
/**
* 获取分页数组
* @param unknown $page 当前页面数
* @param unknown $goodsCount 商品总数
* @param unknown $pageLength 每个页面展示页面数
*/
public static function getPageArr($page, $goodsCount, $pageCountLength, $pageLength) {
//页面总数
$allPageCount = ceil($goodsCount / $pageLength);
//如果页面总是比长度短,设定页面长度为页面总数
if ($allPageCount <= $pageCountLength) {
$allPageCount = ceil($goodsCount / $pageLength);
} // www.xfcodes.com
//总页面数一页展示完
if ($allPageCount <= $pageCountLength) {
for ($i = 0; $i < $allPageCount; $i ++) {
$arr[] = array('page' => $i + 1);
}
return $arr;
}
//前后的长度
$halfLength = floor($pageCountLength / 2);
//因为太小,所以放原来位置,左边
if ($page <= $halfLength) {
$arr = array();
for ($i = 0; $i < $pageCountLength; $i ++) {
$arr[] = array('page' => $i + 1);
}
return $arr;
}
//太大,只取到边缘,超出也只取到边缘
if ($page > $allPageCount - floor($pageCountLength / 2)) {
for ($i = -$pageCountLength; $i < 0; $i ++) {
$arr[] = array('page' => $allPageCount + $i + 1);
}
return $arr;
}
//中间的数,把中间的取出来
for ($i = -$halfLength; $i < $pageCountLength - $halfLength; $i ++) {
$arr[] = array('page' => $page + $i);
}
return $arr;
}
}
二、php分页类代码
代码:
class Helper_Page{
/** 总信息数 */
var $infoCount;
/** 总页数 */
var $pageCount;
/** 每页显示条数 */
var $items;
/** 当前页码 */
var $pageNo;
/** 查询的起始位置 */
var $startPos;
/** 下一页 */
var $nextPageNo;
/** 上一页 */
var $prevPageNo;
function Helper_Page($infoCount, $items, $pageNo)
{
$this->infoCount = $infoCount;
$this->items = $items;
$this->pageNo = $pageNo;
$this->pageCount = $this->GetPageCount();
$this->AdjustPageNo();
$this->startPos = $this->GetStartPos();
}
function AdjustPageNo()
{
if($this->pageNo == '' || $this->pageNo < 1)
$this->pageNo = 1;
if ($this->pageNo > $this->pageCount)
$this->pageNo = $this->pageCount;
}
/**
* 下一页
*/
function GoToNextPage()
{
$nextPageNo = $this->pageNo + 1;
if ($nextPageNo > $this->pageCount)
{
$this->nextPageNo = $this->pageCount;
return false;
}
$this->nextPageNo = $nextPageNo;
return true;
}
/**
* 上一页
*/
function GotoPrevPage()
{
$prevPageNo = $this->pageNo - 1;
if ($prevPageNo < 1)
{
$this->prevPageNo = 1;
return false;
}
$this->prevPageNo = $prevPageNo;
return true;
}
function GetPageCount()
{
return ceil($this->infoCount / $this->items);
}
function GetStartPos()
{
return ($this->pageNo - 1) * $this->items;
}
}
php+mysql分页类的入门实例的更多相关文章
- php+Mysql分页 类和引用详解
一下内容为专用于分页的类以及具体的方法和解析.<?php class Page { private $total; //数据表中总记录数 private $listRows; //每页显示行数 ...
- php分页类代码带分页样式效果(转)
php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...
- 简单易用的分页类实例代码PHP
<?php /*********************************************** * @类名: page * @参数: $myde_total - 总记录数 * $m ...
- php四个常用类封装 :MySQL类、 分页类、缩略图类、上传类;;分页例子;
Mysql类 <?php /** * Mysql类 */ class Mysql{ private static $link = null;//数据库连接 /** * 私有的构造方法 */ pr ...
- 分享自己用的php分页类实例源码
分享一个我自己用着的php分页类实例源码,供大家参考,具体内容如下: <?php /** file: page.class.php 完美分页类 Page */ class Page { priv ...
- DedeCMS织梦动态分页类,datalist标签使用实例
<?php require_once(dirname(__FILE__)."/include/common.inc.php");//载入基础文件 require_once(D ...
- 资源(1)----封装类(连接数据库mysql,分页)
一,链接MYSQL数据库 class DBDA{ public $host="localhost";//服务器地址 public $uid="root";//数 ...
- mybatis 详解(二)------入门实例(基于XML)
通过上一小节,mybatis 和 jdbc 的区别:http://www.cnblogs.com/ysocean/p/7271600.html,我们对 mybatis有了一个大致的了解,下面我们通过一 ...
- mybatis 详解(三)------入门实例(基于注解)
1.创建MySQL数据库:mybatisDemo和表:user 详情参考:mybatis 详解(二)------入门实例(基于XML) 一致 2.建立一个Java工程,并导入相应的jar包,具体目录如 ...
随机推荐
- MongoDB - Introduction to MongoDB, BSON Types
BSON is a binary serialization format used to store documents and make remote procedure calls in Mon ...
- Nginx - HTTP Configuration, the Location Block
Nginx offers you the possibility to fine-tune your configuration down to three levels — at the proto ...
- C#算法基础之快速排序
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- ansible安装(批量执行命令
rpm安装 下载epl源 : Download the latest epel-release rpm from:http://dl.fedoraproject.org/pub/epel/6/x86 ...
- sqlserver 关于快照
数据库快照:是数据库某一时间点的视图,快照涉及最初目的是为了报表服务,快照还可以和镜像结合来达到读写分离的目的 数据库快照:是sqlserver数据库的只读静态视图快照的作用:1 提供了一个静态的视图 ...
- Yii zii.widgets.grid 隐藏列 方便js获取隐藏值
array( 'name' => $data->is_audit, 'value' => '$data->is_audit', 'headerHtmlOptions' => ...
- .NET的JSNO 序列化跟反序列化
由于本人最近在写webservice,之前一直都同通过AJAX,在服务端处理业务,但是最近需要写一些接口给其他人用,需要使用jsno的序列化与反序列化,什么是jsno就不多说,jsno的好处也不多说, ...
- Swift结构体与类
在面向过程的编程语言(如C语言)中,结构体用得比较多,但是面向对象之后,如在C++和Objective-C中,结构体已经很少使用了.这是因为结构体能够做的事情,类完全可以取而代之.而Swift语言却非 ...
- (转)设置Win7防火墙规则 顺畅访问局域网
在Windows 7系统的电脑上搭建WAMP环境后,发现在局域网中其他电脑不能访问.有朋友告诉小强,这可能是因为当时Windows 7自带的防火墙屏蔽了80端口,只需要重新设置规则就可以了. 点击Wi ...
- (转)使用 Advanced Installer 打包 一键安装Web应用程序
使用 Advanced Installer 打包 一键安装Web应用程序 安装预览: 资源下载: 示例安装包 操作流程: 1.新建Asp.net Application. 2.设置 ...