php分页为mysql结果

时间:2012-09-17 23:56:23

标签: php mysql pagination

我知道我可能会再次询问它但是我尝试了分页上可用的问题,但无法正确理解dem ...需要知道对以下查询的结果进行分页的方法:

$query = "SELECT * FROM info WHERE Cat1 = 'novel'";
$result = mysql_query($query);
if (!$result) die ("DAtabase acces faild bc : ". mysql_error());

echo " <ul class=listbkwide2>";

while($data = mysql_fetch_object($result))
{
$id = $data->id;
$name = $data->Bname ;
$continent = $data->Bauthor;

    echo "  <li class=bkd><a href='details.php?bid=$id'> 
         <img src='images/sbs/$name.jpg'  title='$name' alt=''>
      <ul class=showcasetitle> <span> $name </span> </ul>
       <p class=authname> By    <span> $continent</span></p>  
      ";
}
echo " </ul> ";
ini_set('display_errors', '1');
mysql_close();

1 个答案:

答案 0 :(得分:1)

您需要维护偏移量,然后在查询中添加LIMIT子句。

[LIMIT {[offset,] row_count | row_count OFFSET offset}]

请参阅the doc