啊,一般的分页显示代码:
   //在变量$number中存放的是数据库中所有$flag=1的留言版,显示的流言总数
  // $offset是每页显示时的偏移量,
   //$see表示当前页
   #$all表示留言版显示的页数
$number=mysql_rum_rows($result);
..........
$query="select username,email,text,time,serial";
$query.="from notebook where flag=1,order bu time desc limit $offset,5";
........
$see=$offset/5+1;
$all=$number/5;
$all=(int)$all+1;
<?php
if($offset!=0)
{
    $preoffset=$offset-5;
    echo"a href=board.php?offset=$preoffset>上一也</a>\n";
    }
if(($offset+5)<$number){
   $newoffset=$offset+5;
   echo"<a href=board.php?offset=$newoffset>下一也</a>\n";
}
?>
//$preoffset中存放的是前一也的偏移量,$newoffset中存放的是最后一也的偏移量。

解决方案 »

  1.   

    /* 这是我想实现分页功能的代码 */ 
     <?
     if(empty($offset)){$offset=0;}
     $fp=fopen("board.txt","r");
     $array=file("board.txt");
     $result=count($array);
     $nowpage=$offset/4+1;
     $all=$result/4;
     $all=(int)$all+1;
     ?>
        <td width="18%"><div align="center"><font size="2">
    共有<font color="red"><? echo $all;?></font>页</font></div></td>
        <td width="19%"><div align="center"><font size="2">
    目前第<font color="red"><? echo $nowpage;?></font>页 </font></div></td> <td width="9%"><div align="center"><font size="2">
    <? if($offset!=0){   $preoffset=$offset-4;
     echo " <a href=\"board.php?offset=$preoffset\">前页</a>";
     }
      ?>  </font></div></td>  
     <td width="9%"><div align="center"><font size="2">
     <?
        if(($offset+4)<$result){
    $newoffset=$offset+4;
    echo " <a href=\"board.php?offset=$newoffset\">后页</a>";
      }
     ?>
       </font></div></td>
      </tr>
    </table>
    /* 下面是我想在每一面显示4条留言的代码不知错在哪儿 */
    <?
    for($i=1;$i<5;$i++)
    {
    $str=fgets($fp);
    $data=explode("##",$str);
    echo "<table width=\"100%\" height=\"192\" border=\"1\" cellpadding=\"0\"
    .......
    }
    ?>