error_reporting('E_ALL&~E_NOTICE');  
$page=$_GET['p'];
$host="localhost";
$username="root";
$password="";
$db="fy";
$pageSize=10;
$showPage=5; $conn=mysqli_connect($host,$username,$password);
if(!$conn){
echo "数据库连接失败";
exit;
}

mysqli_select_db($conn,$db);
$sql="SELECT * FROM page order by id ASC LIMIT ".($page-1)*$pageSize .",{$pageSize}";


mysqli_query($conn,"SET NAMES UTF8");
$result=mysqli_query($conn,$sql);
echo "<div class='content'>";
echo "<table border=1 cellspacing=0 width=30% align=center>";
echo "<tr><td>ID</td><td>NAME</td></tr>";
while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>{$row['ID']}</td>";
echo "<td>{$row['NAME']}</td>";
echo "<tr>";
}
echo "</table>";
echo "</div>";
mysqli_free_result($result);
//获取数据总条数
$total_sql="SELECT COUNT(*)FROM page";
$total_result=mysqli_fetch_array(mysqli_query($conn,$total_sql));
$total=$total_result[0];
$total_pages=ceil($total/$pageSize);
//关闭数据库
mysqli_close($conn);



$total_sql="SELECT COUNT(*)FROM page";获取数据,然后是
$total_result=mysqli_fetch_array(mysqli_query($conn,$total_sql));
作为关联数组赋值还会形成数字数组
$total=$total_result[0];意思是取出数组数组比如是124条
$total_pages=ceil($total/$pageSize);
然后是124/10进一既可以了,为什么,因为进一代表算上加上4还算一行啊



while ($row = mysqli_fetch_assoc($result)) {
echo "<tr>";
echo "<td>{$row['ID']}</td>";
echo "<td>{$row['NAME']}</td>";
echo "<tr>";
}意思是获取到数据以后,就形成关联数组,也就是idNAME为下标啦,赋值给$row一个一个来形成数据排列下来。