时间:2021-07-01 10:21:17 帮助过:3人阅读
- function _setPage($baseUrl, $total, $start, $limit, $parm="")
- {
- if($total != 0) $pages = $total/$limit; else $pages = 0;
- if(empty($start)) $start=0;
- if(empty($limit)) $limit=20;
- if($start>$total)$start=$total-$limit;
- if($start<0) $start=0;
- if($limit<0) $limit=0;
- if($limit>100) $limit=100;
- //$start = $start - $top;
- $showpage = 10;
- $currentpage=$start/$limit;
- if($currentpage<5){
- $pageno=0;
- $i=0;
- } else{
- if($currentpage+10 > $total/$limit ){
- $pageno=$currentpage -5;
- }else{
- $pageno=$currentpage - 5;
- }
- $i=$pageno*$limit;
- }
- if($total==0) $currentpage = -1;
- $strPage = "总[" . ($currentpage + 1) . "/" . ceil($pages) . "]页 ";
- $page=0;
- $strPage .= "";
- if($start/$limit > $showpage)
- {
- $tmp = ($pageno - 1)* $limit;
- $strPage.= "<<";
- }
- while($i < $total)
- {
- if($start/$limit ==$pageno)
- {
- $strPage .= "<font color="red">". ($pageno + 1) ." </font>";
- }
- else
- {
- $strPage .= "".($pageno + 1)." ";
- }
- $pageno++;
- $page++;
- $i+=$limit;
- if($page > $showpage)
- {
- $strPage.= ">>";
- break;
- }
- }
- if($start>0){
- $strPage .= " 首页 ";
- }else{
- $strPage .= " 首页 ";
- }
- if($start>0){
- $strPage .= " 上一页 ";
- }
- if($start+$limit< $total){
- $strPage .= " 下一页 ";
- }
- if($start+$limit< $total){
- $strPage .= " 尾页 ";
- }else{
- $strPage .= " 尾页 ";
- }
- return $strPage;
- }
- <br><font color="#e78608">------解决方案--------------------</font><br>为什么要JS的?
- <br><font color="#e78608">------解决方案--------------------</font><br>$baseUrl为页面基本的url,比如说index.php?m=table&a=list<br>$total为你要分页的记录的总数,用来计算有多少页的.<br>$start为当前页开始的记录条数.<br>$limit为每页显示的条数,这个可以定为常量.<br>$parm为额外的参数,比如说你在$baseUrl的基础上又添加了一个search='news'的话,可以在这里添加,以便追加到url里.
- <br><font color="#e78608">------解决方案--------------------</font><br>学习。