分页类:

<?php

/* * *********************************************
* @类名: page
* @参数: $myde_total - 总记录数
* $myde_size - 一页显示的记录数
* $myde_page - 当前页
* $myde_url - 获取当前的url
* @功能: 分页实现
* @作者: 宋海阁
*/ class Page { private $myde_total; //总记录数
private $myde_size; //一页显示的记录数
private $myde_page; //当前页
private $myde_page_count; //总页数
private $myde_i; //起头页数
private $myde_en; //结尾页数
private $myde_url; //获取当前的url
/*
* $show_pages
* 页面显示的格式,显示链接的页数为2*$show_pages+1。
* 如$show_pages=2那么页面上显示就是[首页] [上页] 1 2 3 4 5 [下页] [尾页]
*/
private $show_pages; public function __construct($myde_total = , $myde_size = , $myde_page = , $myde_url, $show_pages = ) {
$this->myde_total = $this->numeric($myde_total);
$this->myde_size = $this->numeric($myde_size);
$this->myde_page = $this->numeric($myde_page);
$this->myde_page_count = ceil($this->myde_total / $this->myde_size);
$this->myde_url = $myde_url;
if ($this->myde_total < )
$this->myde_total = ;
if ($this->myde_page < )
$this->myde_page = ;
if ($this->myde_page_count < )
$this->myde_page_count = ;
if ($this->myde_page > $this->myde_page_count)
$this->myde_page = $this->myde_page_count;
$this->limit = ($this->myde_page - ) * $this->myde_size;
$this->myde_i = $this->myde_page - $show_pages;
$this->myde_en = $this->myde_page + $show_pages;
if ($this->myde_i < ) {
$this->myde_en = $this->myde_en + ( - $this->myde_i);
$this->myde_i = ;
}
if ($this->myde_en > $this->myde_page_count) {
$this->myde_i = $this->myde_i - ($this->myde_en - $this->myde_page_count);
$this->myde_en = $this->myde_page_count;
}
if ($this->myde_i < )
$this->myde_i = ;
} //检测是否为数字
private function numeric($num) {
if (strlen($num)) {
if (!preg_match("/^[0-9]+$/", $num)) {
$num = ;
} else {
$num = substr($num, , );
}
} else {
$num = ;
}
return $num;
} //地址替换
private function page_replace($page) {
return str_replace("{page}", $page, $this->myde_url);
} //首页
private function myde_home() {
if ($this->myde_page != ) {
return "<a href='" . $this->page_replace() . "' title='首页'>首页</a>";
} else {
return "<p>首页</p>";
}
} //上一页
private function myde_prev() {
if ($this->myde_page != ) {
return "<a href='" . $this->page_replace($this->myde_page - ) . "' title='上一页'>上一页</a>";
} else {
return "<p>上一页</p>";
}
} //下一页
private function myde_next() {
if ($this->myde_page != $this->myde_page_count) {
return "<a href='" . $this->page_replace($this->myde_page + ) . "' title='下一页'>下一页</a>";
} else {
return"<p>下一页</p>";
}
} //尾页
private function myde_last() {
if ($this->myde_page != $this->myde_page_count) {
return "<a href='" . $this->page_replace($this->myde_page_count) . "' title='尾页'>尾页</a>";
} else {
return "<p>尾页</p>";
}
} //输出
public function myde_write($id = 'page') {
$str = "<div id=" . $id . ">";
$str.=$this->myde_home();
$str.=$this->myde_prev();
if ($this->myde_i > ) {
$str.="<p class='pageEllipsis'>...</p>";
}
for ($i = $this->myde_i; $i <= $this->myde_en; $i++) {
if ($i == $this->myde_page) {
$str.="<a href='" . $this->page_replace($i) . "' title='第" . $i . "页' class='cur'>$i</a>";
} else {
$str.="<a href='" . $this->page_replace($i) . "' title='第" . $i . "页'>$i</a>";
}
}
if ($this->myde_en < $this->myde_page_count) {
$str.="<p class='pageEllipsis'>...</p>";
}
$str.=$this->myde_next();
$str.=$this->myde_last();
$str.="<p class='pageRemark'>共<b>" . $this->myde_page_count .
"</b>页<b>" . $this->myde_total . "</b>条数据</p>";
$str.="</div>";
return $str;
} } ?>

PHP页

include_once("config.php");
require_once('page.class.php'); //分页类
$showrow = ; //一页显示的行数
$curpage = empty($_GET['page']) ? : $_GET['page']; //当前的页,还应该处理非数字的情况
$url = "?page={page}"; //分页地址,如果有检索条件 ="?page={page}&q=".$_GET['q']
//省略了链接mysql的代码,测试时自行添加
$sql = "SELECT id,content,addtime FROM wishing_wall";
$total = mysql_num_rows(mysql_query($sql)); //记录总条数
if (!empty($_GET['page']) && $total != && $curpage > ceil($total / $showrow))
$curpage = ceil($total_rows / $showrow); //当前页数大于最后页数,取最后一页
//获取数据
$sql .= " LIMIT " . ($curpage - ) * $showrow . ",$showrow;";
$query = mysql_query($sql);

分页数据显示

<ul class="dates">
<?php while ($row = mysql_fetch_array($query)) { ?>
<li>
<span><?php echo $row['addtime'] ?></span>
<a target="_blank" href="http://www.sucaihuo.com/js"><?php echo $row['content'] ?></a>
</li>
<?php } ?>
</ul>

显示分页条

<div class="showPage">
<?php
if ($total > $showrow) {//总记录数大于每页显示数,显示分页
$page = new page($total, $showrow, $curpage, $url, );
echo $page->myde_write();
}
?>
</div>

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 ...

  10. webpy分页类 + 上传类

    webpy没有分页类.按照php的思路.自己编了一个.数据库用的是sqlite. class Page(object): '''分页类''' def __init__(self,page_size,d ...

随机推荐

  1. js中如何获取页面的Url,域名和端口号

    有时候通过获取上个页面的Url来做一个跳转,获取域名防止非正常访问 获取上一个页面的一个URL,这个URL一般做一个页面的跳转 window.location.href <script>w ...

  2. 【Python】Python 猜年龄的游戏

    游戏规则: 允许用户最多尝试3次 每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y或y, 就继续让其猜3次,以此往复,如果回答N或n,就退出程序 如何猜对了,就直接退出 age= cou ...

  3. Java Machine Learning Tools & Libraries--转载

    原文地址:http://www.demnag.com/b/java-machine-learning-tools-libraries-cm570/?ref=dzone This is a list o ...

  4. bzoj2699 更新

    题意 对于一个数列A[1..N],一种寻找最大值的方法是:依次枚举A[2]到A[N],如果A[i]比当前的A[1]值要大,那么就令A[1]=A[i],最后A[1]为所求最大值.假设所有数都在范围[1, ...

  5. 【hdu5306】Gorgeous Sequence 线段树区间最值操作

    题目描述 给你一个序列,支持三种操作: $0\ x\ y\ t$ :将 $[x,y]$ 内大于 $t$ 的数变为 $t$ :$1\ x\ y$ :求 $[x,y]$ 内所有数的最大值:$2\ x\ y ...

  6. Mybatis笔记五:Mybatis的全局配置文件Configuration.xml讲解

    从 XML 中构建 SqlSessionFactory 每个基于Mybatis应用都是以一个SqlSessionFactory实例为中心.SqlSessionFactory实例可以由SqlSessio ...

  7. [ACM][2018南京预赛]Magical Girl Haze

    一.题面 样例输入: 15 6 11 2 21 3 42 4 33 4 13 5 64 5 2 样例输出: 3 二.思路 关键词:分层BFS 考试时觉得题干意思很清晰——求可将k条边赋值为0的最短路. ...

  8. 【bzoj2402】陶陶的难题II

    Portal -->bzoj2402 Solution 这题的话,看到答案的形式想到分数规划(Portal -->[learning]) 套路一波,记当前二分的\(mid\)为\(\lam ...

  9. 在 Xamarin.Forms 实现页面全屏显示

    NavigationPage.SetHasNavigationBar(this, false); 或者 <ContentPage ... NavigationPage.HasNavigation ...

  10. @Springboot搭建项目controller层接收json格式的对象失败

    今天在使用swagger2测试的时候出错 1.@requestBody注解常用来处理content-type不是默认的application/x-www-form-urlcoded编码的内容,比如说: ...