Home > php教程 > PHP源码 > body text

php 经典的分页函数

WBOY
Release: 2016-06-08 17:29:45
Original
868 people have browsed it

php 经典的分页函数

<script>ec(2);</script>


/**
*分页函数
*
*
*/
function multi($total, $perPage, $curPage, $pageUrl, $maxPages = 0, $page = 10, $autoGoTo = TRUE, $simple = FALSE) {
 $multiPage = '';
 $pageUrl .= strpos($pageUrl, '?') ? '&' : '?';
 $realPages = 1;
 if($total > $perPage) {
  $offset = 2;

  $realPages = @ceil($total / $perPage);
  $pages = $maxPages && $maxPages

  if($page > $pages) {
   $from = 1;
   $to = $pages;
  } else {
   $from = $curPage - $offset;
   $to = $from + $page - 1;
   if($from     $to = $curPage + 1 - $from;
    $from = 1;
    if($to - $from      $to = $page;
    }
   } elseif ($to > $pages) {
    $from = $pages - $page + 1;
    $to = $pages;
   }
  }

  $multiPage = ($curPage - $offset > 1 && $pages > $page ? '1 ...' : '').
   ($curPage > 1 && !$simple ? '' : '');
  for($i = $from; $i    $multiPage .= $i == $curPage ? ''.$i.'' :
    ''.$i.'';
  }

  $multiPage .= ($curPage ››' : '').
   ($to ... '.$realPages.'' : '').
   (!$simple && $pages > $page && !$ajaxtarget ? '' : '');

  $multiPage = $multiPage ? '

'.(!$simple ? ' '.$total.' ' : '').$multiPage.'
' : '';
 }
 $maxpage = $realPages;
 return $multiPage;
}

此函数只要传参数就可以有漂亮的分页效果哦,并且支持select下拉设置调转功能

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!