PHP分页实例
发布时间:2013-09-19 11:33:46来源:阅读(1280)
$page=isset($_GET['page'])?intval($_GET['page']):1;
$num=2;
$db=mysql_connect("localhost","root","");
$select=mysql_select_db("db",$db);
$total=mysql_num_rows(mysql_query("select * from db2"));
$pagenum=ceil($total/$num); //总页数
$offset=($page-1)*$num;
$pre = $page-1; //前一页
$next = $page+1; //后一页
$first = 1; //后一页
$last = $pagenum; //最后也
if($page>$pagenum || $page == 0){
echo "Error : Can Not Found The page .";
exit;
}
$info=mysql_query("select * from db2 limit $offset,$num");
while($it=mysql_fetch_array($info)){
echo $it['aaa']. " " ."
";
}
if($pagenum==1){
echo "首页"." " . "
";
}
if($pagenum >1){
if($page>1 && $page<$pagenum){
echo " 首页 " . " 上一页 " . " 下一页 ". " 最后页 ";
}elseif($page==1){
echo " 首页 " . " 上一页 " . " 下一页 ". " 最后页 ";
}elseif($page==$pagenum){
echo " 首页 " . " 上一页 " . " 下一页 ". " 最后页 ";
}
}
?>