分页问题

分页问题

<html>
<head><title></title>
</head>
<body>
<table width="331" border="0" cellpadding="0" cellspacing="0">
<?php
                include "inc/session.inc.php";
                include "inc/mysql.inc.php";
                $aa = new mysql;
                $aa->link("");
                $lessonid = $_SESSION['id'];
                $temp = $_GET["temp"];
                if($temp !="")
                {
                        $query = "update template set temp_name='$temp' where lesson_id='$lessonid'";
                        $aa->excu($query);
                        echo "<script language=javascript>alert('更换模板成功!')</script>";
                }
                //PHP遍历文件夹下所有文件  这是从文件夹中读出图片
                $handle=opendir('templates/pictemp');  //这里输入其它路径
                $i=0;
                while (false !==($file = readdir($handle))){   //readdir -- 从目录句柄中读取条目
                         if ($file != "." && $file != "..") {
                                        $r = "$file\n";   //输出文件名
                                        //echo $r;
                                        //if($i!=0)
                                        //{
                                                $i++;
?>
  <tr>
    <td width="114" align="center" valign="middle"><a href="folder.php?temp=<?php echo substr($r,0,-5);?>"><?php echo "<img src='templates/pictemp/".$r."'width='130'; height='150'; style='margin-bottom:20px;'>" ?></a></td>
    <td width="60" align="center" valign="middle"><?php echo substr($r,0,-5);?></td>
  </tr>
  <?php
                  //}
                          }
                }
            echo "<a href='folder.php?page='>【上一页】</a>";
                echo "<a href='folder.php?page='>【下一页】</a>";
                closedir($handle);        
  ?>
</table>
</body>
</html>

有那位大侠可以帮忙分分页啊!!!

把所以文件保存在一个数组里。
分页根据索引读取。比如说一个5条
那么第一页就读取索引0-5的数据。。。
毕业了。。。