两款实用php分页代码
分页的就是根据符合条件的总记录除上每页显示的记录就等页数,原理相当简单了公式为 $total = ceil($toalRecord / $perpageNum);,php实例代码如下:
- function outpege($ps,$page)
- {
-
- $max = ($page >= 5)? $page+5:10;
- if($max > $ps)$max =$ps;
- $min =($page-5);
- if($min<1) $min =1;
- if($page>1)$pagelist = "<a href="?page=1">首页</a>";
- for($i=$min;$i<=$max;$i++){
- $pagelist.= ($i!=$page)? "<a href="?page={$i}">{$i}</a>":"<a href="#">{$page}</a>";
- }
- $pagelist.= ($page>=$ps)?'':"<a href="?page={$ps}">尾页</a>";
- return $pagelist;
- }
分页代码二:
-
-
- function page($toalrecord, $perpagenum, $curpage, $url) {
- $total = ceil($toalrecord / $perpagenum);
- $pagearr = array_slice(range(1, $total), max(0, $curpage - ~~($perpagenum / 2)), $perpagenum);
- if($pagearr[0] != 1) {
- array_unshift($pagearr, sprintf("<a href='{$url}%s'><<</a>", $pagearr[0] - 1));
- }
- if($pagearr[count($pagearr)-1] != $total) {
- array_push($pagearr, sprintf("<a href='{$url}%s'>>></a>", $pagearr[count($pagearr)-1] + 1));
- }
- foreach ( $pagearr as $i => &$v ) {
- $v = is_numeric($v) ? "<a href='{$url}{$v}'>{$v}</a>" : $v;
- }
- return "<a href='{$url}'>首页</a>" . implode('', $pagearr) . "<a href='{$url}" . $total . "'>尾页</a>";
- }
- 调用
-
- page(99, 9, page, 'http://www.phpfensi.com/?page=');