• 数组分页去数据


    今天遇到这种情况,图书的ID都存在cookie中,获得的cookie值是

    "537975,467452,556978,464954,2531,1878,457036,3431,469552,537693,465265,462728,484600,561234,559843,554795,"

    而产品经理还要求分页,以前的分页都是对数据库的分页操作。下面是对数据的分页

    #获得的当前页数
    $page       = $_GET('page')?$_GET('page'):1;
    #每页数量
    $pageNum    = 5;
    #获得cookie值
    $playCookie = "537975,467452,556978,464954,2531,1878,457036,3431,469552,537693,465265,462728,484600,561234,559843,554795,"
    #分割数组
    $playCookie = explode(',', trim($playCookie,','));
    $count      = count($playCookie);
    $start      = (page-1)*$pageNum;
    $end        = $start + $pageNum;
    #重新定义一个数组
    $play       = array();
    if ($end > $count) {
      $end      = $count; 
    }
    #分页数据放到新的数组中
    for($i=$start; $i < $end; $i++) {
      $play[]   = $playCookie[$i];
    }

    alex kong
  • 相关阅读:
    web安全
    WCF通信架构
    WCF地址
    WCFContracts(契约)
    分布式中的王者WCF
    SOAP 介绍
    诊所管理软件
    MFC 画图CDC双缓冲
    Linux 启动、关闭、重启网络服务
    C# 除法的小数点问题
  • 原文地址:https://www.cnblogs.com/klj123wan/p/3382808.html
Copyright © 2020-2023  润新知