• php对数组进行分页


     
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    <?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/>";
    }
    ?>
    <?php
    if(!isset($_GET['page']) || $_GET['page']<=1){
    ?>
    <a href="11111111111111.php?page=1">上一页</a>
    <?php }else{ ?>
    <a href="11111111111111.php?page=<?php echo $page-1;?>">上一页</a>
    <?php } ?>
    <?php if($_GET['page']>=$pnum) {?>
    <a href="11111111111111.php?page=<?php echo $pnum;?>">下一页</a>
    <?php }else{ ?>
    <a href="11111111111111.php?page=<?php echo $page+1;?>">下一页</a>
    <?php } ?>
  • 相关阅读:
    Flex 开源框架及工具 枫
    String.Format格式说明 枫
    HTTP服务器状态代码定义(Status Code Definitions) 枫
    像素对应表 枫
    js各种获取屏幕高度宽度 枫
    c#正则表达式帮助 枫
    使用模板引擎Trimpath 枫
    分布式缓存HttpRuntime.cache应用到单点登陆中_优化登陆 枫
    Query this 和 $(this) 的区别 枫
    css and js style 枫
  • 原文地址:https://www.cnblogs.com/vip-deng-vip/p/8005434.html
Copyright © 2020-2023  润新知