您的位置:首页 > 编程语言 > PHP开发

php分页 下标随着页数的增加而向后移

2015-12-20 14:15 537 查看


<?php
$countData =$this->pageSize;
if ($this->page == $this->totalPage){
$yushu = $this->total % $this->pageSize;
if ($yushu != 0) {
$countData = $yushu;
}
}
for($i = 0; $i < $countData; $i++) {
echo "<tr id='tr_". $this->pageList[$i]['account_id']."'>";
echo "<td>".$this->pageList[$i]["account_id"]."</td>";
echo "<td>".$this->pageList[$i]["username"]."</td>";
echo "<td>"."*******"."</td>";
echo "<td>"."<a @link-color href='/account/user_update?id=".$this->pageList[$i]['account_id'].'&'.
"username=".$this->pageList[$i]['username'].'&'.
"password=".$this->pageList[$i]['password']
. "'/>修改信息</a>"
."</td>";
?>

<td>
<a href="javascript:;"  onclick="delete_order('<?php echo $this->pageList[$i][account_id]; ?>')">删除信息</a>
</td>

<?php
echo "</tr>";
}
?>
<div class="pull-right">
<h4>共有用户<?php echo $this->total;?></h4>
</div>
</tbody>
</table>

<div class="pull-right">
<ul class="pagination  " style="display: inline;">
<?php
if ($this->page <= 1) {
?>
<li class="disabled">
<a href="#">上一页</a>
<?php
}
else {
?>
<li>
<a href="user_list?page=<?php echo $this->page - 1; ?>">上一页</a>
<?php
}
?>
</li>
<?php
$start=0;//开始页码
$end=0;//末尾页码
if($this->page>$this->totalPage)
{
$this->page=$this->totalPage;
}

$nums1=intval($this->count/2);//开始项当前的个数
$nums2=$this->count%2==0?$nums1-1:$nums1;//末尾项当前的个数 判断是偶数还是奇数,是偶数就减1

if($this->page<=$this->count - $nums2) //当前页数小于或等于显示页码减去末尾项,当前位置还处于页码范围
{
$start=1;
$end=$this->count;
}else
{
$start=$this->page-$nums1;
$end=$this->page+$nums2;
}

/*当计算出来的末尾项大于总页数*/
if($end>$this->totalPage)
{
$start=($this->totalPage-$this->count)+1;//开始项等于总页数减去要显示的数量然后再自身加1
$end=$this->totalPage;
}
for ($i = $start; $i <= $end; $i++) {
if ($this->page == $i) {
echo "<li><a class='click' href='user_list?page=$i'><font color=red>" . $i . "</font></a> </li>";
} else {
echo "<li><a class='click' href='user_list?page=$i'>" . $i . "</a></li>";
}
}
if ($this->page >= $this->totalPage) {
?>
<li class="disabled">
<a href="#">下一页</a>
<?php
} else {
?>
<li>
<a href="user_list.php?page=<?php echo $this->page + 1; ?>">下一页</a>
<?php
}
?>
</li>
<li>
<span style="font-style: inherit;"> 共<?php echo $this->totalPage;?>页</span>
</li>
</ul>
</div>

<div class="input-group col-md-3 pull-right">
<input type="text"   class="page form-control " placeholder="输入要跳转的页数"/>
<span class="input-group-btn">
<button id="count"  class="btn btn-default" data-toggle="tooltip" data-placement="bottom"
title="跳转到指定页">GO!</button>
</span>
</div>
</div>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: