新写的分页函数
详细见附件中. 这里代码格式都是乱的......直接运行即可
$val){ if($key == $pagestr){ $nowpage = $val; $prepage = $val - 1; $nextpage = $val + 1; }else{ $action .= $key."=".$val."&"; } } $thisname = explode("/", $_SERVER); $filename = $thisname; if($action){ $action .= $pagestr."="; $filename .= "?"; }else{ $action .= $pagestr."="; $filename .= "?"; } $nowpage = empty($nowpage) ? 1 : $nowpage; $totalpage = ceil($totalnum / $perpage); /** * @abstract 上一页下一页的页码 */ if($nowpage <= 1){ $prepage = 1; $nextpage = $totalpage >=2 ? 2 : 1; } if($nowpage >= $totalpage){ $nextpage = $totalpage; $prepage = $totalpage <= 2 ? 1 : $totalpage - 1; } /** * @abstract 本次分页开始和结束的页码 */ if($totalpage <= $linknum){ $begin = 1; $end = $totalpage; }elseif($totalpage > $linknum){ if($nowpage + $behind <= $totalpage){ $begin = $nowpage - $before > 0 ? $nowpage - $before : 1; $end = $begin + $linknum - 1; }else{ $begin = $totalpage - $linknum + 1; $end = $totalpage; } } /** * @abstract 循环输出页码 */ for($i=$begin; $i<=$end; $i++){ if($nowpage == $i){ $linkstr .= "".$i.""; }else{ $linkstr .= "".$i.""; } } $first = $filename.$action."1"; $last = $filename.$action.$totalpage; $pre = $filename.$action.$prepage; $next = $filename.$action.$nextpage; $page = "<<<".$linkstr.">>>"; $page = "limit ".$perpage*($nowpage-1).", ".$perpage; return $page;}$page = page(100, 20);echo $page;?>