這个分页显示怎么只能显示俩页,要怎么修改

qq_35403642 2017-11-30 12:38:24
<?php
/**
* Created by PhpStorm.
* User: Jodo
* Date: 2017-04-17
* Time: 16:10
*/
$currentPageIndex = 1;//当前是第几页
$pageSize = 4;//每页显示3条
$totalPage = 0;//总共有多少页
$totalRecord = 0;//总记录条数
$absoluteIndex = 0;//记录的绝对定位

/**
* 完成分页显示的相关计划与控制
* $totalRecords 当前总的记录行数
*/
function _page($totalRecords)
{
global $currentPageIndex,$pageSize,$totalPage,$absoluteIndex,$totalRecord;
if(isset($_GET['pageIndex']))
{
$currentPageIndex = $_GET["pageIndex"];
if(empty($currentPageIndex) or $currentPageIndex < 0 or !is_numeric($currentPageIndex)){
$page = 1;
}else {
$currentPageIndex = intval($currentPageIndex);
}
}else{
$currentPageIndex = 1;
}
$totalPage = ceil($totalRecords / $pageSize);//ceil(5/2)=3
$absoluteIndex = ($currentPageIndex - 1) * $pageSize;
}

function _paging($pagePath)
{

global $currentPageIndex,$pageSize,$totalPage,$absoluteIndex,$totalRecord;
/*
echo $currentPageIndex.'<br/>';
echo $pageSize.'<br/>';
echo $totalPage.'<br/>';
echo $absoluteIndex.'<br/>';
echo $totalRecord.'<br/>';
*/

if(isset($_GET['pageIndex']))
{
$currentPageIndex = $_GET["pageIndex"];
if(empty($currentPageIndex) or $currentPageIndex < 0 or !is_numeric($currentPageIndex)){
$page = 1;
}else {
$currentPageIndex = intval($currentPageIndex);
}
}else{
$currentPageIndex = 1;
}

//判断可点击状态
if($currentPageIndex >= $totalPage)
{
//说明,到了最后一页:下一页,末页不可点击
$currentPageIndex = $totalPage;
echo "<div style='margin:0 auto; width:400px; height:25px; border:0px solid #F00'>$currentPageIndex/$totalPage  | 共有".$totalPage."条 | <a href='$pagePath". "?pageIndex=1"."'>首页</a> | <a href='$pagePath"."?pageIndex=".($currentPageIndex - 1)."'>上一页</a> | <a>下-页</a> | <a>末页</a></div>";
}elseif($currentPageIndex <= 1)
{
//说明,到了首页:上一页,首页不可点击
$currentPageIndex = 1;
echo "<div style='margin:0 auto; width:400px; height:25px; border:0px solid #F00'>$currentPageIndex/$totalPage  | 共有".$totalPage."条 | <a>首页</a> | <a>上一页</a> | <a href='$pagePath"."?pageIndex=".($currentPageIndex + 1)."'>下-页</a> | <a href='$pagePath"."?pageIndex=$totalPage"."'>末页</a></div>";
}else{
echo "错误";
}
//echo "<div style='margin:0 auto; width:400px; height:25px; border:0px solid #F00'>$currentPageIndex/$totalPage  | 共有12页 | <a href='$pagePath". "?pageIndex=1"."'>首页</a> | <a href='$pagePath"."?pageIndex=".($currentPageIndex - 1)."'>上一页</a> | <a href='$pagePath"."?pageIndex=".($currentPageIndex + 1)."'>下-页</a> | <a href='$pagePath"."?pageIndex=$totalPage"."'>末页</a></div>";
}
...全文
220 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuzuning 2017-11-30
  • 打赏
  • 举报
回复
}else{ echo "错误"; } //echo " 改为 }else//{ // echo "错误"; // } echo "
hongmei85 2017-11-30
  • 打赏
  • 举报
回复
qq_35403642 2017-11-30
  • 打赏
  • 举报
回复
换了种写法 已经成功 谢各位大佬

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧