Home >php教程 >PHP源码 >php 文章分页效果代码

php 文章分页效果代码

WBOY
WBOYOriginal
2016-06-08 17:30:111123browse
<script>ec(2);</script>

/前台分页函数
function multi($num, $perpage, $curpage, $mpurl, $maxpages = 0, $page = 10, $autogoto = TRUE, $simple = FALSE) {
 //global $maxpage;
 $ajaxtarget = !empty($_GET['ajaxtarget']) ? " ajaxtarget="".htmlspecialchars($_GET['ajaxtarget'])."" " : '';

 $multipage = '';
 $mpurl .= strpos($mpurl, '?') ? '&' : '?';
 $realpages = 1;
 if($num > $perpage) {
  $offset = 2;

  $realpages = @ceil($num / $perpage);
  $pages = $maxpages && $maxpages   //$curpage = $curpage

  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 ? ' '.$num.' ' : '').$multipage.'
' : '';
 }
 $maxpage = $realpages;
 return $multipage;
}
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