废话不多说,直接看代码吧 Pager.class.php 代码如下 class Pager{ /** *int总页数 **/ protected $pageTotal ; /** **/ protected $previous ; /** **/ protected $next ; /** *int中间页起始序号 **/ protected $startPage ; /** *int中间页终止序号 **/ pr
废话不多说,直接看代码吧
Pager.class.php 代码如下
- class Pager {
- /**
- *int 总页数
- * */
- protected $pageTotal;
- /**
- * */
- protected $previous;
- /**
- * */
- protected $next;
- /**
- *int 中间页起始序号
- * */
- protected $startPage;
- /**
- *int 中间页终止序号
- * */
- protected $endPage;
- /**
- *int 记录总数
- * */
- protected $recorbTotal;
- /**
- *int 每页显示记录数
- * */
- protected $pageSize;
- /**
- *int 当前显示页
- * */
- protected $currentPage;
- /**
- *string 基url地址
- * */
- protected $baseUri;
- /**
- * @return string 获取基url地址
- */
- public function getBaseUri() {
- return $this->baseUri;
- }
- /**
- * @return int 获取当前显示页
- */
- public function getCurrentPage() {
- return $this->currentPage;
- }
- /**
- * @return int 获取每页显示记录数
- */
- public function getPageSize() {
- return $this->pageSize;
- }
- /**
- * @return int 获取记录总数
- */
- public function getRecorbTotal() {
- return $this->recorbTotal;
- }
- /**
- * @param string $baseUri 设置基url地址
- */
- public function setBaseUri($baseUri) {
- $this->baseUri = $baseUri;
- }
- /**
- * @param int $currentPage 设置当前显示页
- */
- public function setCurrentPage($currentPage) {
- $this->currentPage=$currentPage;
- }
- /**
- * @param int $pageSize 设置每页显示记录数
- */
- public function setPageSize($pageSize) {
- $this->pageSize = $pageSize;
- }
- /**
- * @param int $recorbTotal 设置获取记录总数
- */
- public function setRecorbTotal($recorbTotal) {
- $this->recorbTotal = $recorbTotal;
- }
- /**
- *构造函数
- * */
- public function __construct()
- {
- $this->pageTotal = 0;
- $this->previous = 0;
- $this->next = 0;
- $this->startPage = 0;
- $this->endPage = 0;
- $this->pageSize = 20;
- $this->currentPage = 0;
- }
- /**
- *分页算法
- * */
- private function arithmetic() {
- if ($this->currentPage
- $this->currentPage = 1;
- $this->pageTotal = floor ( $this->recorbTotal / $this->pageSize ) + ($this->recorbTotal % $this->pageSize > 0 ? 1 : 0);
- if ($this->currentPage > 1 && $this->currentPage > $this->pageTotal)
- header ( 'location:' . $this->baseUri . 'page=' . $this->pageTotal );
- $this->next = $this->currentPage + 1;
- $this->previous = $this->currentPage - 1;
- $this->startPage = ($this->currentPage + 5) > $this->pageTotal ? $this->pageTotal - 10 : $this->currentPage - 5;
- $this->endPage = $this->currentPage $this->currentPage + 5;
- if ($this->startPage
- $this->startPage = 1;
- if ($this->pageTotal $this->endPage)
- $this->endPage = $this->pageTotal;
- }
- /**
- *分页样式
- * */
- protected function pageStyle() {
- $result = "共" . $this->pageTotal . "页 ";
- if ($this->currentPage > 1)
- $result .= " . $this->baseUri . "page=1/">9 . $this->baseUri . "page=$this->previous/">3";
- else
- $result .= "9 3";
- for($i = $this->startPage; $i $this->endPage; $i ++) {
- if ($this->currentPage == $i)
- $result .= " $i";
- else
- $result .= " . $this->baseUri . "page=$i/">$i";
- }
- if ($this->currentPage != $this->pageTotal) {
- $result .= " . $this->baseUri . "page=$this->next/">4";
- $result .= " . $this->baseUri . "page=$this->pageTotal/">:";
- } else {
- $result .= " 4 :";
- }
- return $result;
- }
- /**
- *执行分页
- * */
- public function execute() {
- if ($this->baseUri != "" && $this->recorbTotal == 0)
- return "";
- $this->arithmetic();
- return $this->pageStyle ();
- }
- }
调用代码(test.php 代码如下)
- include_once 'Pager.class.php';
- $pager=new Pager();
- if (isset ( $_GET ['page'] ) && ! emptyempty ( $_GET ['page'] ))
- $pager->setCurrentPage($_GET ['page']);
- else
- $pager->setCurrentPage(1);
- $pager->setRecorbTotal(1000);
- $pager->setBaseUri("test.php?");
- echo $pager->execute();
数据库结合 mysql 通用存储过程分页 海量数据分页 就是一个完美的分页了
我们还可继承 Pager 类重写pageStyle方法就可以有不同的样式了. yes ok

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

在php中,可以使用substr()函数来读取字符串后几个字符,只需要将该函数的第二个参数设置为负值,第三个参数省略即可;语法为“substr(字符串,-n)”,表示读取从字符串结尾处向前数第n个字符开始,直到字符串结尾的全部字符。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

查找方法:1、用strpos(),语法“strpos("字符串值","查找子串")+1”;2、用stripos(),语法“strpos("字符串值","查找子串")+1”。因为字符串是从0开始计数的,因此两个函数获取的位置需要进行加1处理。


热AI工具

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

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

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

Dreamweaver CS6
视觉化网页开发工具

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