我怎么顯示的0頁,
<?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 "連接數(shù)據(jù)庫失敗";
}
mysql_select_db($db);
mysql_query('set names utf8');
$querysql="select*from mypage limit ".(($page-1)*10).",10";
if(!$querysql){
echo "數(shù)據(jù)庫中沒有數(shù)據(jù)";
}
$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>";
//釋放結(jié)果
mysql_free_result($result);
//獲取數(shù)據(jù)總數(shù)
$total_sql="select count(*) from mypage";
$total_result=mysql_query($total_sql);
$total=$total_result[0];
//計(jì)算頁數(shù)
$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;
?>
2016-12-10
數(shù)據(jù)庫得有數(shù)據(jù)才行,先輸出總條數(shù)看看有數(shù)據(jù)沒
2016-01-21
就是總頁數(shù)為0,導(dǎo)致后面的做不了。誰幫我找找問題