qq_Jonathan丶Cle_0
2016-01-21 21:27
<?php
header('Content-type:text/html;charset=utf-8');
$page=$_GET['p'];
$host='localhost';
$user='root';
$password='';
$db='msg';
$pageSize=10;
$conn=mysql_connect($host,$user,$password);
if(!$conn){
echo "连接数据库失败";
}
mysql_select_db($db);
mysql_query('set names utf8');
$querysql="select*from mypage limit ".(($page-1)*10).",10";
if(!$querysql){
echo "数据库中没有数据";
}
$result=mysql_query($querysql);
echo "<table border=1 cellspacing=0 width=30%>";
echo "<tr><td>ID</td><td>NAME</td></tr>";
while($row=mysql_fetch_assoc($result)){
echo "<tr>";
echo "<td>{$row['id']}</td>";
echo "<td>{$row['name']}</td>";
echo "</tr>";
}
echo "</table>";
//释放结果
mysql_free_result($result);
//获取数据总数
$total_sql="select count(*) from mypage";
$total_result=mysql_query($total_sql);
$total=$total_result[0];
//计算页数
$total_pages=ceil($total/10);
//显示分页+分页条
$page_banner="<a href='".$_SERVER['PHP_SELF']."?p=".($page-1)."'>上一页</a>";
$page_banner.="<a href='".$_SERVER['PHP_SELF']."?p=".($page+1)."'>下一页</a>";
$page_banner.="共".$total_pages."页";
echo $page_banner;
?>
数据库得有数据才行,先输出总条数看看有数据没
就是总页数为0,导致后面的做不了。谁帮我找找问题
PHP+MySQL分页原理实现
41204 学习 · 185 问题
相似问题