<?php
//加载初始化文件
include ‘../init.php‘;
//加载数据库文件
include DIR_CORE.‘MYSQLDB.php‘;
//给list_father加表示
//$num = $_GET[‘num‘];
//标识页,当前选中的页码数
$pageNum = isset($_GET[‘num‘])?$_GET[‘num‘] : 1;
$pageNum =(int)$pageNum;
//每页显示的条数
$PerPagerows = 4;
//数据的总条数
$sql = "select count(*) from publish";
$result= my_query($sql);
$rows=mysql_fetch_row($result);
$rowCount = $rows[0];
//总页数
$pages = ceil($rowCount/$PerPagerows);
if($pageNum>$pages){
$pageNum=$pages;
}
if($pageNum<=1){
$pageNum=1;
}
//字符串拼凑
$str = "";
//首页
$str .="<a href=‘./list_father.php?num=1‘>首页</a>";
//上一页
$preNum = $pageNum==1 ? 1 : $pageNum-1;
$str .="<a href=‘./list_father.php?num=$preNum‘>上一页</a>";
//显示页码初始页$stratNum
if($pageNum <=5){
$stratNum=1;
}else{
$stratNum=$pageNum-2;
}
if($stratNum >= $pages-5){
$stratNum = $pages-5;
}
if($stratNum<=1){
$stratNum=1;
}
//显示的最大页数
$maxNum = $stratNum +5;
if($maxNum>=$pages){
$maxNum=$pages;
}
//页码数显示页
for($i=$stratNum;$i<=$maxNum;$i++){
if($i==$pageNum){
$str .="<a href=‘./list_father.php?num=$i‘><font color=‘red‘>$i</font></a>";
}else {
$str .="<a href=‘./list_father.php?num=$i‘>$i</a>";
}
}
//下一页
$nextNum = ($pageNum==$pages? $pages : $pageNum+1);
$str .="<a href=‘./list_father.php?num=$nextNum‘>下一页</a>";
//尾页
$str .="<a href=‘./list_father.php?num=$pages‘>尾页</a>";
//提取帖子资源集
$offset = ($pageNum-1)*$PerPagerows;
$sql = "select * from publish order by pub_time desc limit {$offset},{$PerPagerows}";
$result=my_query($sql);
//加载视图文件
include DIR_VIEW.‘list_father.html‘;
//完善视图文件