思路:

通过给页面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. css的position定位终极总结

    relative相对定位是相对于自己的位置定位,absolute绝对定位是向上级一级一级搜索有position属性的div,如果没有找到就相对于body定位

  2. 11、SpringBoot------定时任务

      开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/Springboot/tree/52ef6c0c805913db1e66ed18671c322e ...

  3. 浅谈Docker

    一.为什么使用Docker 软件开发最大的麻烦事之一,就是环境配置.很多人想到,能不能从根本上解决问题,软件可以带环境安装? 也就是说,安装的时候,把原始环境一模一样地复制过来. 目前有两个主流解决方 ...

  4. 浅谈MySQL字符集

      Preface       MySQL use character set & collation to organize the different charater.It provid ...

  5. MySQL中事物的详解

    1. 事物的定义及特性 事务是一组操作数据库的SQL语句组成的工作单元,该工作单元中所有操作要么同时成功,要么同时失败.事物有如下四个特性,ACID简称“酸性”. 1)原子性:工作单元中所有的操作要么 ...

  6. linux 开机自启动 Tomcat

    1.修改脚本文件rc.local:vim /etc/rc.d/rc.local 这个脚本是使用者自定的开机启动程序,可以在里面添加想在系统启动之后执行的脚本或者脚本执行命令 2.添加如下内容: exp ...

  7. fastadmin 后台管理框架使用技巧(持续更新中)

    fastadmin 后台管理框架使用技巧(持续更新中) FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架,具体介绍,请查看文档,文档地址为:https://doc. ...

  8. css 自动换行,超出省略号代替

    overflow : hidden;    text-overflow: ellipsis;    display: -webkit-box;    -webkit-line-clamp: 2;    ...

  9. Multiplication Puzzle ZOJ - 1602

    Multiplication Puzzle ZOJ - 1602 传送门 The multiplication puzzle is played with a row of cards, each c ...

  10. [BSGS]大步小步算法

    问题 BSGS被用于求解离散对数,即同余方程: \[ A^x\equiv B\pmod{P} \] 求\(x\)的最小非负整数解. 保证\(A\perp P\)(互质). 分析 首先,我们根据费马小定 ...