1 <?php 2 $conn = mysql_connect("localhost", "root", "") or die("连接错误"); 3 mysql_select_db("test"); 4 mysql_query("set names utf8"); 5 6 //获取总数量 7 $sql = "select count(*) from wei_test"; 8 $result = mysql_query($sql, $conn); 9 $row = mysql_fetch_row($result); 10 $amount = $row[0]; 11 12 $page_count = 4; 13 14 //获取总页数 15 $page_amount = ceil($amount/$page_count); 16 17 if(!empty($_GET["page"])){ 18 $page = $_GET["page"]; 19 }else{ 20 $page = 1; 21 } 22 23 $sql = "select name from wei_test limit ".($page-1)*$page_count.",".$page_count; 24 $result = mysql_query($sql, $conn); 25 while($row = mysql_fetch_assoc($result)){ 26 echo "name:".$row['name']."<br/>"; 27 } 28 for($i=1;$i<=$page_amount;$i++){ 29 echo "<a href='fenye.php?page=$i'>$i</a> "; 30 } 31 mysql_close($conn); 32 ?>