Home > php教程 > php手册 > php数组分页实现方法,php数组分页

php数组分页实现方法,php数组分页

WBOY
Release: 2016-06-13 08:40:37
Original
952 people have browsed it

php数组分页实现方法,php数组分页

本文实例讲述了php数组分页实现方法。分享给大家供大家参考,具体如下:

<&#63;php
$arr_click = array(
array( 'clicks' => 3, 'clickDate' =>'2010-10-11' ),
array( 'clicks' => 2, 'clickDate' =>'2010-10-10' ),
array( 'clicks' => 3, 'clickDate' =>'2010-10-09' ),
array( 'clicks' => 4, 'clickDate' =>'2010-10-08' ),
array( 'clicks' => 5, 'clickDate' =>'2010-10-13' ),
array( 'clicks' => 7, 'clickDate' =>'2010-10-14' ),
array( 'clicks' => 6, 'clickDate' =>'2010-10-15' ),
array( 'clicks' => 9, 'clickDate' =>'2010-10-16' ),
);
if(!isset($_GET['page']))
{
  $page = 1;
}
else
{
 $page=$_GET['page'];
}
$size=3;//每页显示的记录数
$pnum = ceil(count($arr_click) / $size); //总页数,ceil()函数用于求大于数字的最小整数
//用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度)
$newarr = array_slice($arr_click, ($page-1)*$size, $size);
for($i=0;$i<count($newarr);$i++)
{
 echo $newarr[$i]['clickDate']."<br/>";
}
&#63;>
<&#63;php
if(!isset($_GET['page']) || $_GET['page']<=1){
&#63;>
<a href="11111111111111.php&#63;page=1">上一页</a>
<&#63;php }else{ &#63;>
<a href="11111111111111.php&#63;page=<&#63;php echo $page-1;&#63;>">上一页</a>
<&#63;php } &#63;>
<&#63;php if($_GET['page']>=$pnum) {&#63;>
<a href="11111111111111.php&#63;page=<&#63;php echo $pnum;&#63;>">下一页</a>
<&#63;php }else{ &#63;>
<a href="11111111111111.php&#63;page=<&#63;php echo $page+1;&#63;>">下一页</a>
<&#63;php } &#63;>

Copy after login

更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP数组(Array)操作技巧大全》、《PHP数学运算技巧总结》、《php正则表达式用法总结》、《PHP+ajax技巧与应用小结》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家PHP程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template