最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
PHP中常用的分页类总结
时间:2022-06-24 18:08:14 编辑:袖梨 来源:一聚教程网
php基本分页
| 代码如下 | 复制代码 |
|
// database connection info // find out how many rows are in the table // number of rows to show per page // get the current page or set a default // if current page is greater than total pages... // the offset of the list, based on current page // get the info from the db // while there are rows to be fetched... /****** build the pagination links ******/ // if not on page 1, don't show back links // loop to show links to range of pages around current page // if not on last page, show forward and last page links |
|
先看一个常用的php分页类
| 代码如下 | 复制代码 |
|
/* $tbl_name=""; //your table name "; n"; //previous button if ($page > 1) $pagination.= ""; else $pagination.= "� previous"; //pages if ($lastpage { for ($counter = 1; $counter { if ($counter == $page) $pagination.= "$counter"; else $pagination.= ""; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page { for ($counter = 1; $counter { if ($counter == $page) $pagination.= "$counter"; else $pagination.= ""; } $pagination.= "..."; $pagination.= ""; $pagination.= ""; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= ""; $pagination.= ""; $pagination.= "..."; for ($counter = $page - $adjacents; $counter { if ($counter == $page) $pagination.= "$counter"; else $pagination.= ""; } $pagination.= "..."; $pagination.= ""; $pagination.= ""; } //close to end; only hide early pages else { $pagination.= ""; $pagination.= ""; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter { if ($counter == $page) $pagination.= "$counter"; else $pagination.= ""; } } } //next button if ($page $pagination.= ""; else $pagination.= "next �"; $pagination.= " } ?>
while($row = mysql_fetch_array($result)) =$pagination?> |
|
实例
| 代码如下 | 复制代码 |
|
class PageView{ $this->totalNum = $count;//总记录数 $this->hasNextPage = $this->pageNo >= $this->pageCount ?false:true; }else if($this->pageNo > $this->pageCount - 4){ /*** "; if(!empty($pageList)){ if($this->pageCount >1){ if($this->hasPrePage){ $pageString = $pageString .""; } foreach ($pageList as $k=>$p){ if($this->pageNo == $p){ $pageString = $pageString ."" . $this->pageNo . ""; continue; } if($p == -1){ $pageString = $pageString ."..."; continue; } $pageString = $pageString .""; } if($this->hasNextPage){ $pageString = $pageString .""; } } } $pageString = $pageString .(" return $pageString; } } ?> |
|
css代码
| 代码如下 | 复制代码 |
|
--> |
|
在php页面中的调用方法
| 代码如下 | 复制代码 |
|
$pageNo = $_GET['pageNo']; |
|
相关文章
- 超星学生登录入口-超星学习通一键登录 01-30
- 赛氪大英赛报名入口-赛氪竞赛官网首页速点 01-30
- 抖币充值官网入口-抖音抖币充值官网直通 01-30
- j站(Jable)网页版登录入口地址-j站(Jable)海外版国际站网页登录入口地址 01-30
- 奇漫屋在线看漫画:海量国漫日漫全库,每日准时连载更新 01-30
- 无广告漫画app排行榜2026-免费无广告漫画app推荐 01-30