php通用分页种
php通用分页类
<?phpinterface ILink{ public function parse($page,$param);}?>
?
<?phprequire 'ILink.php';class LinkAdapter implements ILink{ /** * @param unknown_type $page * @param unknown_type $param */ public function parse($page, $param) { $temp="共{$page->getAllPage()}页,第{$page->getCurrentPage()}页 "; $links=$this->getLinkString($param); if($page->hasPrevious())$temp.="<a href="%24links=%22.(%24page->getCurrentPage()-1).%22">上一页</a> ";else{$temp.="上一页 ";} for($i=$page->getCurrentPage();$igetAllPage()&&$igetPerRecords();$i++) { $temp.="<a href="%24links=%24i">{$i}</a> "; } if($page->hasNext())$temp.="<a href="%24links=%22.(%24page->getCurrentPage()+1).%22">下一页</a> ";else{$temp.="下一页 ";} return $temp; } public function getLinkString($param) { $str=""; $attr=$_GET; unset($attr[$param]); if($attr) { foreach($attr as $key=>$val) { if($str=="") { $str.="?$key=$val"; } else { $str.="&$key=$val"; } } $str.="&$param"; } else { $str.="?$param"; } return $str; }}?>
??
<?phpclass Page { private $allPage;#总页数 private $allRecords;#总记录数 private $perRecords;#单页记录数 private $currentPage=1;#当前页面 /** * @return the $allPage */ public function getAllPage() { return $this->allPage; } /** * @return the $allRecords */ public function getAllRecords() { return $this->allRecords; } /** * @return the $perRecords */ public function getPerRecords() { return $this->perRecords; } /** * @return the $currentPage */ public function getCurrentPage() { return $this->currentPage; } /** * @param $allPage the $allPage to set */ public function setAllPage($allPage) { $this->allPage = ($allPage%$this->perRecords == 0)?($allPage/$this->perRecords):($allPage/$this->perRecords+1); $this->allPage=intval($this->allPage); } /** * @param $allRecords the $allRecords to set */ public function setAllRecords($allRecords) { $this->allRecords = $allRecords; } /** * @param $perRecords the $perRecords to set */ public function setPerRecords($perRecords) { $this->perRecords = $perRecords; } /** * @param $currentPage the $currentPage to set */ public function setCurrentPage($currentPage) { if ($currentPage currentPage = 1; else if ($currentPage > $this->allPage) $this->currentPage =$this->allPage; else $this->currentPage=$currentPage; } public function hasNext() { return $this->currentPageallPage; } public function hasPrevious() { return $this->currentPage>1; } public function getEndIndex() { return ((($this->currentPage-1)*$this->perRecords)+$this->perRecords)>$this->allRecords?((($this->currentPage-1)*$this->perRecords)+$this->perRecords)-$this->allRecords:$this->perRecords; } public function getStartIndex() { return ($this->currentPage-1)*$this->perRecords; }}?>
?
<?phprequire 'Page.php';require'LinkAdapter.php';class Pager { private $list=array(); private $page;#分页对象 private $param;#页面请求参数 public function __construct($list) { $this->list=$list; $this->page=new Page(); } /** * * @param unknown_type $rows 显示的数据量 * @param unknown_type $current 当前页 */ public function init($rows=5,$current) { $this->page->setAllRecords(count($this->list)); $this->page->setPerRecords($rows); $this->page->setAllPage(count($this->list)); $this->page->setCurrentPage($current); $this->list=array_slice($this->list,$this->page->getStartIndex(),$this->page->getEndIndex()); } /** * 获取分页变量 */ public function getVar() { return $this->list; } /** * @return the $param */ public function getParam() { return $this->param; } /** * @param $param the $param to set */ public function setParam($param) { $this->param = $param; } /** * 加载插件信息,获取生成的链接,装饰器模式 * @param unknown_type $link */ public function getLink($link=null) { if(!empty($link)||!(($link instanceof ILink)))$link=new LinkAdapter(); return $link->parse($this->page,$this->param); }}?>
?
<?php include'lib/Pager.php'; $target=array(); for($i=0;$i<=100;$i++){$target[]=$i;} $page=new Pager($target); $page->setParam("page"); $page->init(30,$_REQUEST['page']); $list=$page->getVar(); foreach($list as $val): echo $val.'<br>'; endforeach; echo $page->getLink();?>
?下载

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Function means function. It is a reusable code block with specific functions. It is one of the basic components of a program. It can accept input parameters, perform specific operations, and return results. Its purpose is to encapsulate a reusable block of code. code to improve code reusability and maintainability.

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Detailed explanation of the role and function of the MySQL.proc table. MySQL is a popular relational database management system. When developers use MySQL, they often involve the creation and management of stored procedures (StoredProcedure). The MySQL.proc table is a very important system table. It stores information related to all stored procedures in the database, including the name, definition, parameters, etc. of the stored procedures. In this article, we will explain in detail the role and functionality of the MySQL.proc table

In this article, we will learn about enumerate() function and the purpose of “enumerate()” function in Python. What is the enumerate() function? Python's enumerate() function accepts a data collection as a parameter and returns an enumeration object. Enumeration objects are returned as key-value pairs. The key is the index corresponding to each item, and the value is the items. Syntax enumerate(iterable,start) Parameters iterable - The passed in data collection can be returned as an enumeration object, called iterablestart - As the name suggests, the starting index of the enumeration object is defined by start. if we ignore

Implementing data paging and display optimization in Vue projects. In Vue projects, when a page needs to display a large amount of data, data paging and display optimization usually need to be performed to improve user experience. This article will introduce how to use Vue to implement data paging and display optimization. , and provide specific code examples. 1. Data paging Data paging refers to dividing a large amount of data into multiple pages according to certain rules and displaying them on the page. You can use the following steps to implement data paging in a Vue project: Define the data source. First, define a
