本文实例讲述了PHP分页显示的方法。分享给大家供大家参考,具体如下:
PHP;">
PHP
header("content-type:text/html;charset=utf-8");
$currentpage = 1;
if(isset($_GET['page']))
$currentpage = $_GET['page'];
//连接数据库
$link = MysqL_connect("localhost","root","") or die('连接失败');
MysqL_select_db('myschool');
MysqL_query('set names utf8');
$sql ="SELECT count(*) as 'count' from student";//查询记录的sql语句
$result = MysqL_query($sql);
$arr = MysqL_fetch_array($result);
$count = $arr['count'];
$pagesize = 3;
$pages = ceil($count/$pagesize);//共多少页
$prepage = $currentpage -1;
if($prepage<=0)
$prepage=1;
$nextpage = $currentpage+1;
if($nextpage >= $pages){
$nextpage = $pages;
}
$start =($currentpage-1) * $pagesize;//起始位置
$sql = "SELECT * from student limit $start,$pagesize";
echo $sql;
// $sql = "select * from student";
$result = MysqL_query($sql);
?>
<Meta charset="UTF-8">
Document
" rel="external nofollow" >上一页下一页