通用分页类
通用分页类(以Codeigniter测试) CodeIgniter ?php if( ! defined('BASEPATH')) die('No Access');/** * 分页类 * * @author wangaibowangaibo@boqii.net * @version 1.0.0 * @link http://www.du52.com/text.php?id=551 */class Page_list { /** * 总数据 *
通用分页类(以Codeigniter测试) CodeIgniter
<?php if( ! defined('BASEPATH')) die('No Access'); /** * 分页类 * * @author wangaibo<wangaibo@boqii.net> * @version 1.0.0 * @link http://www.du52.com/text.php?id=551 */ class Page_list { /** * 总数据 * @var int */ private $total; /** * 每页显示数据 * @var int */ private $size; /** * 当前页数 * @var int */ private $page; /** * 页数列表左右页数 * @var int */ private $len; /** * 总页数 * @var int */ private $page_total; /** * 页码列表 * @var array */ private $page_list; /** * 基准地址 * @var string */ private $base_url; /** * 替换标志 * @var string */ private $place; /** * 分页样式 * @var string */ private $style; /** * 构造函数 * * @param array $config 配置数组 */ public function __construct($config = array()){ // 初始化默认值 $this->total = 0; $this->size = 20; $this->page = 1; $this->len = 4; $this->page_total = 1; $this->page_list = array(); $this->base_url = '?page=-page-'; $this->place = '-page-'; $this->style = $this->get_default_style(); $this->initialize($config); } /** * 初始化分页 * * @param array $config 配置数组 */ public function initialize($config = array()){ // 取得配置值 if(is_array($config)){ if(array_key_exists('total', $config)) $this->total = @intval($config['total']); if(array_key_exists('size', $config)) $this->size = @intval($config['size']); if(array_key_exists('page', $config)) $this->page = @intval($config['page']); if(array_key_exists('len', $config)) $this->len = @intval($config['len']); if(array_key_exists('base_url', $config)) $this->base_url = @strval($config['base_url']); if(array_key_exists('place', $config)) $this->place = @strval($config['place']); if(array_key_exists('style', $config)) $this->style = @strval($config['style']); } // 修正值 if($this->total<0) $this->total = 0; if($this->size<=0) $this->size = 20; if($this->page<=0) $this->page = 1; if($this->len<=0) $this->len = 4; // 执行分页算法 $this->page_total = ceil($this->total/$this->size); if($this->page_total<=0) $this->page_total = 1; if($this->page>$this->page_total) $this->page = $this->page_total; if($this->page-$this->len>=1){ for($i=$this->len; $i>0; $i--){ $this->page_list[] = $this->page - $i; } }else{ for($i=1; $i<$this->page; $i++){ $this->page_list[] = $i; } } $this->page_list[] = $this->page; if($this->page+$this->len<=$this->page_total){ for($i=1; $i<=$this->len; $i++){ $this->page_list[] = $this->page + $i; } }else{ for($i=$this->page+1; $i<=$this->page_total; $i++){ $this->page_list[] = $i; } } } /** * 默认分页样式 * * @return string */ public function get_default_style(){ $style = '<style type="text/css">'; $style .= ' div.page_list { margin:0;padding:0;overflow:hidden;zoom:1;}'; $style .= ' div.page_list a {display:block;float:left;height:20px;line-height:21px; font-size:13px;font-weight:normal;font-style:normal;color:#133DB6;text-decoration:none;margin:0 3px;padding:0 7px;overflow;zoom:1;}'; $style .= ' div.page_list a.page_list_act { font-size:13px;padding:0 6px;}'; $style .= ' div.page_list a:link, div.page_list a:visited { background:#FFF;border:1px #EEE solid;text-decoration:none;}'; $style .= ' div.page_list a:hover, div.page_list a:active { background:#EEE;text-decoration:none;}'; $style .= ' div.page_list strong { display:block;float:left;height:20px;line-height:21px;font-size:13px;font-weight:bold;font-style:normal;color:#000;margin:0 3px;padding:0 8px;overflow:hidden;zoom:1;}'; $style .= ' </style>'; return $style; } /** * 是否是第一页 * * @return bool */ public function is_first_page(){ return $this->page == 1; } /** * 获取第一页页码 * * @return int */ public function get_first_page(){ return 1; } /** * 是否是最后一页 * * @return bool */ public function is_last_page(){ return $this->page == $this->page_total; } /** * 获取最后一页页码 * * @return int */ public function get_last_page(){ return $this->page_total; } /** * 是否存在上一页 * * @return bool */ public function has_prev_page(){ return $this->page > 1; } /** * 是否存在下一页 * * @return bool */ public function has_next_page(){ return $this->page < $this->page_total; } /** * 获取上一页页码 * * @return int */ public function get_prev_page(){ return $this->has_prev_page() ? $this->page - 1 : $this->page; } /** * 获取下一页页码 * * @return int */ public function get_next_page(){ return $this->has_next_page() ? $this->page + 1 : $this->page; } /** * 获取当前页页码 * * @return int */ public function get_curr_page(){ return $this->page; } /** * 获取总数据数 * * @return int */ public function get_total(){ return $this->total; } /** * 获取每页显示数据数 * * @return int */ public function get_size(){ return $this->size; } /** * 获取总页数 * * @return int */ public function get_total_page(){ return $this->page_total; } /** * 构建并返回分页代码 * * @param string $base_url 基准地址 * @param string $place 替换标志 * @param string $style 分页样式 * @return string 分页HTML代码 */ public function display($base_url = '', $place = '', $style = ''){ if($base_url==='') $base_url = $this->base_url; if($place==='') $place = $this->place; if($style==='') $style = $this->style; $str = $style.'<div class="page_list">'; if( ! $this->is_first_page()){ $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_first_page(), $base_url).'">首页</a>'; } if($this->has_prev_page()){ $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_prev_page(), $base_url).'">上一页</a>'; } foreach($this->page_list as $v){ if($v==$this->page){ $str .= '<strong>' . $v . '</strong>'; }else{ $str .= '<a href="'.str_replace($place, $v, $base_url).'">'.$v.'</a>'; } } if($this->has_next_page()){ $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_next_page(), $base_url).'">下一页</a>'; } if( ! $this->is_last_page()){ $str .= '<a class="page_list_act" href="'.str_replace($place, $this->get_last_page(), $base_url).'">尾页</a>'; } $str .= '</div>'; return $str; } } ?>
<?php if( ! defined('BASEPATH')) die('No Access'); class Pagelist extends CI_Controller { public function page(){ $this->load->helper('url'); $page = $this->input->get('page'); $page = @intval($page); if($page<=0) $page = 1; $this->load->library('page_list',array('total'=>10000,'size'=>16,'page'=>$page)); $pl = $this->page_list->display(site_url('pagelist/page/page/-page-')); $this->load->view('pagelist', array('pl' => $pl)); } } ?>
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>分页测试</title> </head> <body> <?php echo $pl; ?> </body> </html>


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

热门话题

PHP开发:如何实现表格数据排序和分页功能在进行Web开发中,处理大量数据是一项常见的任务。对于需要展示大量数据的表格,通常需要实现数据排序和分页功能,以提供良好的用户体验和优化系统性能。本文将介绍如何使用PHP实现表格数据的排序和分页功能,并给出具体的代码示例。排序功能实现在表格中实现排序功能,可以让用户根据不同的字段进行升序或降序排序。以下是一个实现表格

furmark怎么看?1、在主界面中设置“运行模式”和“显示模式”,还能调整“测试模式”,点击“开始”按钮。2、等待片刻后,就会看到测试结果,包含了显卡各种参数。furmark怎么算合格?1、用furmark烤机,半个小时左右看一下结果,基本上在85度左右徘徊,峰值87度,室温19度。大号机箱,5个机箱风扇口,前置两个,上置两个,后置一个,不过只装了一个风扇。所有配件都没有超频。2、一般情况下,显卡的正常温度应该在“30-85℃”之间。3、就算是大夏天周围环境温度过高,正常温度也是“50-85℃

如何使用JavaScript实现表格分页功能?随着互联网的发展,越来越多的网站都会使用表格来展示数据。在一些数据量较大的情况下,需要将数据进行分页展示,以提升用户体验。本文将介绍如何使用JavaScript实现表格分页功能,并提供具体的代码示例。一、HTML结构首先,我们需要准备一个HTML结构来承载表格和分页按钮。我们可以使用<tab

新派幻想仙侠MMORPG《诛仙2》“无为测试”即将于4月23日开启,在原著千年后的诛仙大陆,会发生怎样的全新仙侠冒险故事?六境仙侠大世界,全日制修仙学府,自由自在的修仙生活,仙界中的万般妙趣都在等待着仙友们亲自前往探索!“无为测试”预下载现已开启,仙友们可前往官网下载,开服前无法登录游戏服务器,激活码可在预下载安装完成后使用。《诛仙2》“无为测试”开放时间:4月23日10:00——5月6日23:59诛仙正统续作全新仙侠冒险篇章《诛仙2》以《诛仙》小说为蓝图,在继承原著世界观的基础上,将游戏背景设

《三角洲行动》于今日(3月7日)将开启一场名为“代号:ZERO”的大规模PC测试。而在上周末,这款游戏在上海举办了一次线下快闪体验活动,17173也有幸受邀参与其中。此次测试距离上一次仅仅相隔四个多月,这不禁让我们好奇,在这么短的时间内,《三角洲行动》将会带来哪些新的亮点与惊喜?四个多月前,我已先行在线下品鉴会和首测版本中体验了《三角洲行动》。当时,游戏仅开放了“危险行动”这一模式。然而,《三角洲行动》在当时的表现已然令人瞩目。在各大厂商纷纷涌向手游市场的背景下,如此一款与国际水准相媲美的FPS

MyBatis是一个优秀的持久层框架,它支持基于XML和注解的方式操作数据库,简单易用,同时也提供了丰富的插件机制。其中,分页插件是使用频率较高的插件之一。本文将深入探讨MyBatis分页插件的原理,并结合具体的代码示例进行说明。一、分页插件原理MyBatis本身并不提供原生的分页功能,但可以借助插件来实现分页查询。分页插件的原理主要是通过拦截MyBatis

如何利用Layui开发一个具有分页功能的数据展示页面Layui是一个轻量级的前端UI框架,提供了简洁美观的界面组件和丰富的交互体验。在开发中,我们经常会遇到需要展示大量数据并进行分页的情况。以下是一个利用Layui开发的具有分页功能的数据展示页面的示例。首先,我们需要引入Layui的相关文件和依赖。在html页面的<head>标签中加入以下代

Vue组件实战:分页组件开发介绍在Web应用程序中,分页功能是必不可少的一个组件。一个好的分页组件应该展示简洁明了,功能丰富,而且易于集成和使用。在本文中,我们将介绍如何使用Vue.js框架来开发一个高度可定制化的分页组件。我们将通过代码示例来详细说明如何使用Vue组件开发。技术栈Vue.js2.xJavaScript(ES6)HTML5和CSS3开发环
