<?php
/**
* 分页链接生成函数
* $page URL传递的page值
* $max_page 最大页码值
* $show_page_num 页面中显示多少页码
*/
function makePageHtml($page, $max_page, $show_page_num = 5) {
//将首页的链接存入字符串$page_html中
/*******Begin********/
$page_html='<a href="?page=1">首页</a> ';
/*******end*********/
//根据当前页码$page计算出它的所在分组,以及需要显示的第一页$i和最后一页$max_i
/*******Begin********/
$page_grep=ceil($page/$show_page_num);
$i=$show_page_num*($page_grep-1)+1;
$max=$page_grep*$show_page_num;
$max_i=($max<=$max_page)?$max:$max_page;
/*******end*********/
for ($i; $i <= $max_i; $i++) {
//判断是否有上一个页面分组,若有则向$page_html中添加"<"的链接
/*******Begin********/
if(($i+$show_page_num-1) % $show_page_num==0 && $i>1){
$page_html .='<a href="?page=' . ($i-1) . '"<</a> ';
}
/*******end*********/
//判断是否为当前选中页,并添加入$page_html。这是因为当前选择页的链接与其他页的链接不同
/*******Begin********/
if($i==$page){
$page_html .='<a class = "curl" href="?page=' . $i . '">' . $i . '</a> ';
}else{
$page_html .='<a href="?page=' . $i . '">' . $i . '</a> ';
}
/*******end*********/
//判断是否有下一页,若有则向$page_html中添加">"的链接
/*******Begin********/
if($i % $show_page_num==0 && $i < $max_page){
$page_html .='<a href="?page=' . ($i+1) . '">></a> ';
}
/*******end*********/
}
//将尾页的链接存入字符串$page_html中
/*******Begin********/
$page_html .='<a href="?page=' . $max_page . '">尾页</a> ';
/*******end*********/
//返回显示分页链接的字符串
return $page_html;
}
require "showList.php";