php+mysql分页类的简单代码

时间:2016-02-25 06:16:26来源:网络
导读:php+mysql分页类的简单代码,二个php分页类代码,对商品进行分页展示,当前页面数,每个页面展示页面数,简单实用的php分页代码。
 
php+mysql分页类的简单代码

一、php分页类代码

复制代码代码示例:
class PageModel {  
    /** 
     * 获取分页数组 
     * @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分页类的入门实例的更多相关文章

  1. php+Mysql分页 类和引用详解

    一下内容为专用于分页的类以及具体的方法和解析.<?php class Page { private $total; //数据表中总记录数 private $listRows; //每页显示行数 ...

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

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

  3. 简单易用的分页类实例代码PHP

    <?php /*********************************************** * @类名: page * @参数: $myde_total - 总记录数 * $m ...

  4. php四个常用类封装 :MySQL类、 分页类、缩略图类、上传类;;分页例子;

    Mysql类 <?php /** * Mysql类 */ class Mysql{ private static $link = null;//数据库连接 /** * 私有的构造方法 */ pr ...

  5. 分享自己用的php分页类实例源码

    分享一个我自己用着的php分页类实例源码,供大家参考,具体内容如下: <?php /** file: page.class.php 完美分页类 Page */ class Page { priv ...

  6. DedeCMS织梦动态分页类,datalist标签使用实例

    <?php require_once(dirname(__FILE__)."/include/common.inc.php");//载入基础文件 require_once(D ...

  7. 资源(1)----封装类(连接数据库mysql,分页)

    一,链接MYSQL数据库 class DBDA{ public $host="localhost";//服务器地址 public $uid="root";//数 ...

  8. mybatis 详解(二)------入门实例(基于XML)

    通过上一小节,mybatis 和 jdbc 的区别:http://www.cnblogs.com/ysocean/p/7271600.html,我们对 mybatis有了一个大致的了解,下面我们通过一 ...

  9. mybatis 详解(三)------入门实例(基于注解)

    1.创建MySQL数据库:mybatisDemo和表:user 详情参考:mybatis 详解(二)------入门实例(基于XML) 一致 2.建立一个Java工程,并导入相应的jar包,具体目录如 ...

随机推荐

  1. 转:Nginx+ffmpeg的HLS开源服务器搭建配置及开发详解

    转:http://itindex.net/detail/51186-nginx-ffmpeg-hls 本文概述: 至目前为止,HLS 是移动平台上非常重要并十分流行的流媒体传输协议.做移动平台的流媒体 ...

  2. SNMP监控一些常用OID的总结

    做网络监控的人对SNMP的协议肯定够很熟悉,下面罗列出一些常见的OID说明,方便大家省去查阅相关资料的麻烦. 系统参数(1.3.6.1.2.1.1) OID 描述 备注 请求方式 .1.3.6.1.2 ...

  3. Android之图片应用

    package com.example.imagescale; import android.os.Bundle; import android.app.Activity; import androi ...

  4. 返回页面,主页面不刷新window.history.go(-1),主页面刷新window.location.go(-1)

    返回上一页,不刷新 window.history.go(-1) 返回上一页,刷新 window.location.go(-1)

  5. UIView-4-EventForViews(在view上加入button时候的事件处理)

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  6. C++转到C#历程零基础知识(持续增加)

    1.命名空间.类和源文件的关系:几个源文件用同一个命名空间时候,那么这几个源文件中的各个类之间的调用时可行的.他不会根据你的源文件分离而分开,因为最终编译后生成的是dll,这里来看你的几个源文件是没有 ...

  7. jqGrid API 全

    JQGrid是一个在jquery基础上做的一个表格控件,以ajax的方式和服务器端通信. JQGrid Demo 是一个在线的演示项目.在这里,可以知道jqgrid可以做什么事情. 下面是转自其他人b ...

  8. switch的case中不能做定义

    switch的case中不能做定义 只能给语句 error: a label can only be part of a statement and a declaration is not a st ...

  9. [java学习笔记]java语言基础概述之运算符&程序流程控制&for循环嵌套

    一.运算符 算数运算符 +,-,*,/,%,++,-- 1.+,-,*,/ 整数除以整数的结果为舍弃了小数部分的整数. 2.%:取余 %左右都为正数,左边小于右边结果为左边值,如,4%5=4 %左边大 ...

  10. centos mail 不能发邮件

    http://alfred-long.iteye.com/blog/1836488 (参考) 最近centos 6.4突然不能发邮件了, 直接用 mail命令测试也不收不到邮件 以下参考大侠们的经验后 ...