PHP实现网页翻页

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>PHP分页</title>
</head>
<body>
<?php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "root";
$mysql_database = "taoleshi_data";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password) or die("couldn't open SQL Server $servername <br>");
$page=$_GET["page"];
if( isset($_POST["page"]) && $_POST["page"]!="")
{
     $page=$_POST['page'];
}
if($page=="")
{     
$page=1;
}
if(is_numeric($page))
{     
     $page_size=12;  //每页多少条数据     
     $query="select count(*) as total from area_class";     
     $result = mysql_db_query($mysql_database,$query,$conn);
     $row= mysql_fetch_row($result);      $message_count=$row[0];
      $page_count=ceil($message_count/$page_size);
     $offset=($page-1)*$page_size;
      $result=mysql_db_query($mysql_database,"select * from area_class limit $offset,$page_size",$conn);
     while($row = mysql_fetch_row($result))
     {         
            echo "$row[0],$row[1],$row[2]<br>";     
     }
}
?> ==========================================================================================================<br> 当前页码:<?php echo $page;?>/<?php echo $page_count;?> 记录条数:<?php echo $message_count;?>

<form   method="POST" action="<?php echo $PHP_SELF ?>" target="_self">

<?php     

if($page!=1)

     {

         echo "<a href=IndexAndroid.php?page=1>首页</a> | ";

         echo "<a href=IndexAndroid.php?page=".($page-1).">上一页</a>   ";

     }

?> 

             <input type=submit value="goto">

     <input type="text" size=4 name="page">

<?php

     if($page<$page_count)

     {

         echo "<a href=IndexAndroid.php?page=".($page+1).">下一页</a> | ";

         echo "<a href=IndexAndroid.php?page=".$page_count.">尾页</a>";

     }

     mysql_free_result($result);

     mysql_close($conn); ?>                     
</form>

</body>

</html>

posted @ 2013-07-25 11:04  寂夜冷风  阅读(823)  评论(0编辑  收藏  举报