我写了段代码,想从数据库中调出是“计算机”类的图书,然后将它分页显示,可以显示第一页,但显示不了下一页,好像是第二页没数据似的,(共查出8本计算机类的图书,每页显示3本啊)我的代码是:
<?php if($page==""){$page=1;}; ?>
<?php
$link=mysql_connect("$localhost","$root","$root")||die("无法连接数据库!");
$db=mysql_select_db("test")||die("选择数据库失败!");
$type=$_POST["select"];
if($page){
$page_size=3;
$sql1="select count(*) as total from db_book where type='".$type."'";
$result1=mysql_query($sql1);
$message_count=mysql_result($result1,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$sql2="select * from db_book where type='".$type."'  limit $offset,$page_size";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
?>  <tr>
    <td width="90"><div align="center" class="STYLE2">第<?php echo $rows[id]; ?>条</div></td>
    <td width="350"><div align="center" class="STYLE2"><?php echo $rows[bookname]; ?></div></td>
    <td width="90"><div align="center" class="STYLE2"><?php echo $rows[type]; ?></div></td>
    <td width="200"><div align="center" class="STYLE2"><?php echo $rows[zuozhe]; ?></div></td>
    <td width="280"><div align="center" class="STYLE2"><?php echo $rows[cbs]; ?></div></td>
    <td width="90"><div align="center" class="STYLE2"><?php echo $rows[price]; ?></div></td>
  </tr>
<?php } } ?>