思路:

通过给页面url传递get参数,来控制每页的sql查询(mysql关键词:limit),实现分页查询

代码:

 class getpage{

     public $pagenum;
public $pagecontents;
public $sql;
public $url;
public function __construct($a){ $this->pagecontents = $a;
$this->url = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
}
//获取分页数
public function createpage($sql){ $this->sql = $sql;
$conn = mysql_connect('localhost','root','root');
if(!$conn){ die(mysql_error());
}
mysql_select_db('class',$conn)or die(mysql_error());
mysql_query("set names 'utf8'");
$handle = mysql_query($sql);
$row = array();
while($r = mysql_fetch_row($handle)){ $row[] = $r;
}
//假如除的结果为小数,则进1来保证分页数量
$pagenum = count($row)/$this->pagecontents;
$this->pagenum = ceil($pagenum); }
//替换page参数
private function replacestr(){
if(isset($_GET['page'])){
return str_replace("?page=".@$_GET['page'],"", $this->url);
}else{
@$_GET['page'] = 0;
}
}
//页面分页显示
public function createstyle(){ for($i=0;$i<$this->pagenum;$i++){ echo "<button><a href='".$this->replacestr($this->url)."?page=".$i*$this->pagecontents."'>".(1+$i)."</a></button>";
}
}
public function getdata(){ $where = " limit ".(@$_GET['page']).",".$this->pagecontents;
$this->sql .= $where;
$handle = mysql_query($this->sql);
$arr = array();
while($r = mysql_fetch_assoc($handle)){
$arr[] = $r;
}
return $arr;
} }

PHP 自制分页类的更多相关文章

  1. php实现的分页类

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

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

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

  3. php分页类

    1.需求 学会php分页类的使用 2.参考例子 CI的分页类 3.代码部分 <?php class pagination{ public $pagesize=20; public $pagein ...

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

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

  5. php 简单分页类

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

  6. PHP简单漂亮的分页类

    本文介绍一款原生的PHP分页类,分页样式有点类似bootstrap. <?php /* * ********************************************* * @类名 ...

  7. ThinkPHP 分页类的使用及退出功能的实现

    /* ThinkPHP设置编码统一: 一.数据库设置为utf8_bin 二.HTML页面设置charset=utf-8,而且检查文档编码格式是否是utf-8.phpDesigner8设置方式为“文件- ...

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

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

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

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

随机推荐

  1. Hibernate 提供session的工具类HibernateUtils

    package cn.itcast.utils; import java.sql.Connection; import java.sql.SQLException; import org.hibern ...

  2. linux系统中 redis 保存数据的5种形式 linux后端模式启动 jedis无法通过IP地址和端口号访问如何修改linux防火墙

    vim修改redis.conf配置文件(我的已经复制到虚拟机的/usr/local/redis/bin目录下)为daemonize yes, 以后端模式启动 ./redis-server redis. ...

  3. javabeans 内省 introspector BeanUtils

    javaBeans 属性的概念 不只是字段,而是其get set 方法 且该get方法有返回值的称为属性,继承Object类的getClass方法 package com.swift.demo1; p ...

  4. 电话状态监听 - iOS

    今天接到一个监听状态的需求,当使用 App 时若电话介入需要对当前状态进行监听操作(注:并非通话内容),根据不同的状态实行相关的需求操作,废话不多说步骤如下. 首先,常规操作先引用对应的头文件,来为后 ...

  5. 触发ionic弹窗区域外的方法

    最近项目需要在页面弹窗的时候需要点击弹窗区域外的地方,其实也就是点击页面HTML就可以关闭弹窗, 首先在controller通过js获取到html的dom节点,然后绑定点击事件,话不多说上代码:   ...

  6. 字符串替换For linux C

    1.临时空间给了个1024,不需要可减少长度. 2.结果只用用strcpy了,没校验. bool Replace(char *str,const char *src, const char *des) ...

  7. MyBatis单列工厂的实现

    MyBatis单列工厂的实现 SqlSessionFactoryUtils package com.utils; import org.apache.ibatis.io.Resources; impo ...

  8. python 计算提成代码

    while True: with open('8564.txt') as f: r = f.readlines() start = input("请输入要查询的日期,例如20180101 : ...

  9. Shell学习——数组

    1.普通数组:只能用整数作为索引1.1.赋值[root@client02 ~]# array[0]=test1[root@client02 ~]# array[1]=test2[root@client ...

  10. ethereum(以太坊)(十二)--应用(一)__集资(构造函数/映射)

    pragma solidity ^0.4.4; contract funder{ //0xca35b7d915458ef540ade6068dfe2f44e8fa733c //0x14723a09ac ...