测试图例:
效果图:
实现代码:
if($rows == 0){
return $data = array(
'page' => $page,'MaxPage' => $MaxPage,'MinPage' => $MinPage,'ServerPage' => $ServerPage,'PageData' => $PageData,'PageShowData' => $PageShowData
);
}
//得到最大<a href="https://www.jb51.cc/tag/fenye/" target="_blank" class="keywords">分页</a>和最小<a href="https://www.jb51.cc/tag/fenye/" target="_blank" class="keywords">分页</a>
$MaxPage = intval($rows / $num);
$double = $rows % $num;
if($double > 0.000000001)
{
$MaxPage += 1;
}
$MinPage = 1;
$ServerPage = 1;
//得到<a href="https://www.jb51.cc/tag/yema/" target="_blank" class="keywords">页码</a>的全部项目
for($i = 1; $i <= $MaxPage; $i++ ){
$PageData[$i] = $i;
}
//对<a href="https://www.jb51.cc/tag/yema/" target="_blank" class="keywords">页码</a>进行正确性改正
if($page < $MinPage){
$page = 1;
}
if($page > $MaxPage){
$page = 1;
}
/*<a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" class="keywords">生成</a><a href="https://www.jb51.cc/tag/xianshi/" target="_blank" class="keywords">显示</a>的<a href="https://www.jb51.cc/tag/yema/" target="_blank" class="keywords">页码</a><a href="https://www.jb51.cc/tag/biaoqian/" target="_blank" class="keywords">标签</a>*/
//<a href="https://www.jb51.cc/tag/shengcheng/" target="_blank" class="keywords">生成</a>左侧的<a href="https://www.jb51.cc/tag/daima/" target="_blank" class="keywords">代码</a>快
if($page == $MinPage){
$PageShowData[1] = $page;
}
if($page > $MinPage){
$PageShowData[1] = $MinPage;
// $PageShowData[2] = $page - 1; // <<
$PageShowData[2] = '<<'; // <<
if($page -2 > $MinPage ){
$PageShowData[3] = $page - 2;
$PageShowData[4] = $page - 1;
}elseif($page -2 == $MinPage){
$PageShowData[3] = $page - 1;
}
//确定选中的页码代码快
$PageShowData[count($PageShowData) + 1] = $page;
}
$COUNT = count($PageShowData) + 1;
//生成右侧的代码块
if($page == $MaxPage){
return $data = array(
'page' => $page,'PageShowData' => $PageShowData
);
}
if($page < $MaxPage) {
if($MaxPage - $page >= 2){
$j = 1;
for($i = $COUNT; $i <= $length ; $i++){
$PageShowData[$i] = $page + $j;
$j ++;
if($PageShowData[$i] == $MaxPage -1){
break;
}
}
}
$COUNT = count($PageShowData) + 1;
// $PageShowData[$COUNT] = $page + 1; //>>
$PageShowData[$COUNT] = '>>';
$PageShowData[$COUNT + 1] = $MaxPage;
//得到选中的参数
$ServerPage = $PageShowData[$COUNT-1] + 1;
if($ServerPage > $MaxPage){
$ServerPage = 1;
}
return $data = array(
'page' => $page,'PageShowData' => $PageShowData
);
}
}
本文出自 IT985博客
原文链接:https://www.f2er.com/php/20411.html