page 简单易懂 分页
基础分页功能
<?php
class Page{
//$count是用户设定的值
public $a;
function pages($count,$page_num,$url)
{
//总页数
$page_sum=ceil($count/$page_num);
//当前页
if(isset($_GET['page'])){
$page = $_GET['page'];
}else{
$page = 1;
}
//偏移量
$limit = ($page-1)*$page_num;
$this -> a = "limit $limit,$page_num";
//上一页
if($page-1<=0){
$last = 1;
}else{
$last = $page-1;
}
//下一页
if($page+1>=$page_sum){
$next = $page_sum;
}else{
$next = $page+1;
}
$str = "";
$str.="<a href='".$url."page=1' >首页</a> ";
$str.="<a href='".$url."page=$last' >上一页</a> ";
$str.="<a href='".$url."page=$next' >下一页</a> ";
$str.="<a href='".$url."page=$page_sum' >尾页</a>";
return $str;
}
}
?>