<?php
//连接
数据库
$con =
mysql_connect("localhost","root","");
mysql_select_db("xueshengchu",$con);
mysql_query("set names utf8");
$pageSize = 5; //每页显示数据条数
$result = mysql_query("select * from stu_msg");
$totalNum = mysql_num_rows($result); //数据总条数
$totalPageCount = intval($totalNum/$pageSize); //总页数
//判断当前页是哪一页
$nowPage = isset($_GET['page']) ? intval($_GET['page']) : 1;
//上一页
$prev = ($nowPage-1 <= 0) ? 1 : $nowPage-1;
//下一页
$next = ($nowPage+1 >= $totalPageCount) ? $totalPageCount : $nowPage+1;
//偏移量
$offset = ($nowPage-1)*$pageSize;
/*可以取数据啦,
sql语句分页原理
* select * from table limit $offset,$size分页执行语句
*/ www.jb200.com
$sql = "select * from stu_msg limit $offset,$pageSize";
$result = mysql_query($sql,$con);
while($arr = mysql_fetch_array($result)){
echo $arr['mid'].$arr['content']."<br />";
}
echo "<a href="".$_SERVER['PHP_SELF']."?page=1">首页</a>";
echo "<a href="".$_SERVER['PHP_SELF']."?page=".$prev."">上一页</a>";
echo "<a href="".$_SERVER['PHP_SELF']."?page=".$next."">下一页</a>";
echo "<a href="".$_SERVER['PHP_SELF']."?page=".$totalPageCount."">尾页</a>";
?>