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

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>";
}
...全文
185 3 点赞 打赏 收藏 举报
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
xuzuning 2017-11-30
}else{ echo "错误"; } //echo " 改为 }else//{ // echo "错误"; // } echo "
  • 打赏
  • 举报
回复
hongmei85 2017-11-30
  • 打赏
  • 举报
回复
qq_35403642 2017-11-30
换了种写法 已经成功 谢各位大佬
  • 打赏
  • 举报
回复
相关推荐
发帖
基础编程
加入

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
帖子事件
创建了帖子
2017-11-30 12:38
社区公告
暂无公告