Home >php教程 >PHP源码 >php 经典的分页函数

php 经典的分页函数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:29:45921browse

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下拉设置调转功能

Statement:
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