<?php
$x=20;
$qh=mysql_query(“SELECT COUNT(*) AS num FROM table ORDER BY id desc”);
$data=mysql_fetch_array($qh);
$num=$data['num'];
$offset=$_GET['offset'];
if(empty($offset))
{    
 $offset=0;
}    
$result=mysql_query(“select * from table order by id desc LIMIT $offset,$x”,$con);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
……
}
if($offset)
{
    $preoffset=$offset-$x;    
   echo “<a href=’$PHP_SELF?offset=$preoffset’>前一页</a>”.”\t”; 
}    
$pages=ceil($num/$x);
for($i=1;$i<=$pages;$i++)
{    
   $newoffset=$x*$i-$x;
 if($offset==$newoffset){
 echo “<a href=’$PHP_SELF?offset=$newoffset’>i</a>”.”\t”;
 }else{
   echo “<a href=’$PHP_SELF?offset=$newoffset’>$i</a>”.”\t”;
 }
}  
if($pages!=0&&(($offset/$x)+1)!=$pages)
{    
   echo “<a href=’$PHP_SELF?offset=$newoffset’>下一页</a>”.”\t”;   
}
?>

  • Share/Bookmark

相关日志