PHP简单漂亮的分页类
本文介绍一款原生的PHP分页类,分页样式有点类似bootstrap。
- <?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 = 1, $myde_size = 1, $myde_page = 1, $myde_url, $show_pages = 2) {
- $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 < 0)
- $this->myde_total = 0;
- if ($this->myde_page < 1)
- $this->myde_page = 1;
- if ($this->myde_page_count < 1)
- $this->myde_page_count = 1;
- if ($this->myde_page > $this->myde_page_count)
- $this->myde_page = $this->myde_page_count;
- $this->limit = ($this->myde_page - 1) * $this->myde_size;
- $this->myde_i = $this->myde_page - $show_pages;
- $this->myde_en = $this->myde_page + $show_pages;
- if ($this->myde_i < 1) {
- $this->myde_en = $this->myde_en + (1 - $this->myde_i);
- $this->myde_i = 1;
- }
- 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 < 1)
- $this->myde_i = 1;
- }
- //检测是否为数字
- private function numeric($num) {
- if (strlen($num)) {
- if (!preg_match("/^[0-9]+$/", $num)) {
- $num = 1;
- } else {
- $num = substr($num, 0, 11);
- }
- } else {
- $num = 1;
- }
- return $num;
- }
- //地址替换
- private function page_replace($page) {
- return str_replace("{page}", $page, $this->myde_url);
- }
- //首页
- private function myde_home() {
- if ($this->myde_page != 1) {
- return "<a href='" . $this->page_replace(1) . "' title='首页'>首页</a>";
- } else {
- return "<p>首页</p>";
- }
- }
- //上一页
- private function myde_prev() {
- if ($this->myde_page != 1) {
- return "<a href='" . $this->page_replace($this->myde_page - 1) . "' 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 + 1) . "' 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 > 1) {
- $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;
- }
- }
- ?>
分页演示地址:http://www.sucaihuo.com/php/223.html
PHP简单漂亮的分页类的更多相关文章
- THinkPHP简单漂亮的分页类 DownLoad
PHP include_once("config.php"); require_once('page.class.php'); //分页类 $showrow = 10; //一页显 ...
- 一个简单的php分页类代码(转载)
入门级php分页类 原文地址:http://www.xfcodes.com/php/fenye/3608.htm 时间:2015-12-16 20:52:00来源:网络 php分页类. 复制代码代码如 ...
- 简单实用的分页类-python
django自带的分页虽然挺好,但是就想自己弄个通用的 自己写了个分页的类,用的是python, 其他语言改下语法就能用了. #定义好类.class pagemanage: def __init_ ...
- php漂亮的分页类
<?php /* * PHP分页类 * @package Page * @Created 2013-03-27 * @Modify 2013-03-27 * ...
- 一个简单的CI分页类
[php] view plaincopy <span style="font-size:16px;">/** * * 关于 页码有效性的判断需要加在 控制器中判断,即当 ...
- 简单实用的原生PHP分页类
一款简单实用的原生PHP分页类,分页按钮样式简洁美观,页码多的时候显示“...”,也是挺多网站用的效果 核心分页代码 include_once("config.php"); req ...
- php 简单分页类
/** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 privat ...
- 好用的ASP.NET 分页类 简单好用 支持 AJAX 自定义文字
在做网站没用 JS UI控件时 很实用 用法: var ps=new PageString(); /*可选参数*/ ps.SetIsEnglish = true;// 是否是英文 (默认:false) ...
- 用PHP写的一个简单的分页类 1.0版
<?php /* 分页类 用于实现对多条数据分页显示 version:1.0 author:Knight E-Mail:S.Knight.Work@gmail.com Date:2013-10- ...
随机推荐
- 为什么你不应该用angularjs?
AngularJS的问题 为什么你不该用angularjs,https://medium.com/@mnemon1ck/why-you-should-not-use-angularjs-1df5ddf ...
- 【BZOJ-3450】Tyvj1952Easy 概率与期望DP
3450: Tyvj1952 Easy Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 468 Solved: 353[Submit][Status] ...
- jackson处理boolean类型的注意点
在使用jackson处理boolean类型的时候,比如你的java bean有一个boolean类型的字段:isTitle, 默认把这个Java bean 转换为json的时候,这个字段就变成了tit ...
- jqGrid使用方法
1.下载文件 下载jqGrid的软件包,下载地址为:http://www.trirand.com/blog/?page_id=6 下载jQuery文件,下载地址为:http://code.jquery ...
- OpenCV: imshow后不加waitkey无法显示视频
OpenCV显示视频帧时出现一个问题,就是imshow之后若是不加waitkey则无法显示,找了很久也没找到原因. 只是发现也有人发现这个问题: cvWaitKey(x) / cv::waitKe ...
- POJ1185炮兵阵地(状态压缩 + dp)
题目链接 题意:给出一张n * m的地图,其中 有的地方能放大炮,有的地方不能,大炮与上下左右两个单位范围内会相互攻击,问最多能放几个大炮 能放大炮为1不能放大炮为0,把每一行看做一个状态,要除去同一 ...
- jquery 图片浏览功能实现
效果展示: HTML代码: <div id="no3"> <img src="./img/last.png" id="last&qu ...
- 《Java疯狂讲义》(第3版)学习笔记 2 - Java语言的运行机制
内容 1.高级语言的运行机制 2.Java 语言的运行机制 1.高级语言的运行机制 高级语言主要分为编译型语言和解释型语言两类. 编译型语言是指使用专门的编译器.针对特定平台(操作系统)将高级语言源代 ...
- C#读写文本和连接数据库
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 最简单的jQuery插件
<script src="./jquery-1.7.1.min.js"></script><script>;(function($,undefi ...