<div> <div> <ul> <?php $querySel = "select * from table"; $result = mysql_query($querySel) or die(mysql_error()); $total_records = mysql_num_rows($result); //取得总记录数 $page_size = 3; //每页显示的条数 $nums = $total_records; //总条目数 $sub_pages = 5; //每次显示的页数 $totalPage = ceil($total_records/$page_size);//总页数 $pageCurrent = $_GET["page"]; //得到当前是第几页 if(!$pageCurrent) $pageCurrent = 1; //$begin_record = 0; //显示记录的首行序号 $begin_record = ($pageCurrent - 1) * $page_size; if($total_records> 0) { //利用LIMIT关键字获取本页所要显示的记录,注意limit两边要"空格"; $querySel = $querySel. " limit ".$begin_record. ", ".$page_size; $result = mysql_query($querySel); $current_records = mysql_num_rows($result); //取得本页的记录总数 //将查询结果放在$result_show 数组 $result_show = array(); } $i = 0; while($row=mysql_fetch_array($result)) { $result_show[$i] = $row; ?> <li><a href="templates.php?id=<?php echo $result_show[$i]['id'] ?>" target="_blank" class="tmain"><?php echo ($result_show[$i]['title']) ?><img src="/<?php echo ($result_show[$i]['src']) ?>"></a></li> <?php } ?> </ul> </div> <span>总共<?php echo $total_records; ?>条记录 <?php echo $page.'/'.$totalPage; ?></span> <a href="templateslist.php?page=1">首页 </a> <?php if($page>1){//不在第一页du echo '<a href="templateslist.php?page='.($page-1).'">上一页 </a>'; } if($page < $totalPage){//不在最后一页 echo '<a href="templateslist.php?page='.($page+1).'">下一页 </a>'; } ?> <a href="templateslist.php?page=<?php echo $totalPage;?>">尾页</a> </div> |