PHP 分页函数
class page{ /** * 分页 * @param int $total 总数 * @param int $num 每页显示数 * @param int $curpage 当前页码 * @param string $mpurl URL * @param string $ajax ajax * @param int $maxpages 最大 * @param int $page 显示分页数 * @param string $autogoto * @param string $simple * @return string */ public function multiPage($total, $num, $curpage, $mpurl, $ajaxFun = ‘‘, $maxpages = 0, $page = 10, $autogoto = FALSE, $simple = FALSE) { $shownum = $showkbd = TRUE; $lang[‘prev‘] = ‘‹‹‘; $lang[‘next‘] = ‘››‘; $ajaxtarget = ‘‘; $multipage = ‘‘; $mpurl = current(explode(‘&page‘, $mpurl)); $mpurl .= strpos($mpurl, ‘?‘) ? ‘&‘ : ‘?‘; if ($ajaxFun) { $mpurl; } $realpages = 1; $curpage = $curpage ? $curpage : 1; if($total > $num) { $offset = 2; $realpages = @ceil($total / $num); $pages = $maxpages && $maxpages < $realpages ? $maxpages : $realpages; if($page > $pages) { $from = 1; $to = $pages; } else { $from = $curpage - $offset; $to = $from + $page - 1; if($from < 1) { $to = $curpage + 1 - $from; $from = 1; if($to - $from < $page) { $to = $page; } } elseif($to > $pages) { $from = $pages - $page + 1; $to = $pages; } } $multipage = ($curpage - $offset > 1 && $pages > $page ? ‘<a ‘. $this->multiPageUrl($mpurl.‘page=1‘, $ajaxFun) .‘ class="first"‘.$ajaxtarget.‘>1 ...</a>‘ : ‘‘). ($curpage > 1 && !$simple ? ‘<a ‘. $this->multiPageUrl($mpurl.‘page=‘.($curpage - 1), $ajaxFun) .‘ class="prev"‘.$ajaxtarget.‘>‘.$lang[‘prev‘].‘</a>‘ : ‘‘); for($i = $from; $i <= $to; $i++) { $multipage .= $i == $curpage ? ‘<strong>‘.$i.‘</strong>‘ : ‘ <a ‘. $this->multiPageUrl($mpurl.‘page=‘.$i, $ajaxFun) . $ajaxtarget.‘>‘.$i.‘</a> ‘; } $multipage .= ($to < $pages ? ‘ <a ‘. $this->multiPageUrl($mpurl.‘page=‘.$pages, $ajaxFun) .‘ class="last"‘.$ajaxtarget.‘>... ‘.$realpages.‘</a> ‘ : ‘‘). ($curpage < $pages && !$simple ? ‘ <a ‘. $this->multiPageUrl($mpurl.‘page=‘.($curpage + 1), $ajaxFun) .‘class="next"‘.$ajaxtarget.‘>‘.$lang[‘next‘].‘</a> ‘ : ‘‘). ($showkbd && !$simple && $pages > $page && !$ajaxtarget && $autogoto ? ‘<kbd><input type="text" name="custompage" size="3" onkeydown="if(event.keyCode==13) {window.location=\‘‘.$mpurl.‘page=\‘+this.value; return false;}" /></kbd>‘ : ‘‘); $multipage = $multipage ? ‘<div class="pages">‘.‘<span>Total</span> <span>‘.$total.‘</span> ‘.$multipage.‘</div>‘ : ‘‘; } $maxpage = $realpages; return $multipage; } public function multiPageUrl($s, $fun){ if ($fun) { $str = ‘href = "javascript:;" onclick="‘.$fun.‘(\‘‘.$s.‘\‘)" ‘; }else{ $str = ‘href = "‘.$s.‘" ‘; } return $str; } public function css(){ $s = ‘.pages {height: 50px; padding-top: 20px; clear: both;} .pages A,.pages strong{ background-color: #0A4B99; margin-left: 10px; border: 1px solid #818181; color: #FFFFFF; display: block; float: left; height: 20px; padding: 5px 13px 2px 12px; width: auto;} .pages A:HOVER{background-color: #72B3FF} .pages strong{background-color: #fff; color: #000;} .pages span{float: left; padding: 5px 0 2px 12px; color:#0A4B99;font-weight: bold; font-size: 15px;} .pages strong{border: 1px solid #0A4B99;} .next, .prev{font-size: 25px; line-height: 11px;color: yellow !important;}‘; return $s; } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。