php 数组实现分页
//一周之内获取的时间范围
$now_time = time(); $total_week =isset($_REQUEST['total_week']) && ($_REQUEST['total_week'] > 0) ? $_REQUEST['total_week'] : 1; $begin = $now_time - $total_week * 7 * 86400; $statDate = date("Y/m/d", $begin); $end = $now_time -($total_week - 1) * 7 * 86400; $endDate = date("Y/m/d", $end); $pageno = isset($_REQUEST['pageno']) && ($_REQUEST['pageno'] > 0) ? $_REQUEST['pageno'] : 1; $pagesize = 10;
页面刷新分页
//是否已经采集完 if ($pageno < $page_total) { echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; echo '当前第'.$total_week.'周,第'.$pageno.'页,共'.$page_total.'页'; echo '<script>self.location="?total_week='.$total_week.'&pageno='.($pageno + 1).'";</script>'; exit; } else { if ($total_week > 1) { $next_week = $total_week - 1; } else { echo '<script>self.location="xinshengbl.php";</script>'; echo 'ok'; } echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; echo '当前第'.$total_week.'周,第'.$pageno.'页,共'.$page_total.'页'; echo '<script>self.location="?total_week='.$next_week.'&pageno=1";</script>;'; exit; }
return $this->page_array($pagesize,$pageno,$result['goods_list'],0);
数组分页函数
/** * 数组分页函数 核心函数 array_slice * 用此函数之前要先将数据库里面的所有数据按一定的顺序查询出来存入数组中 * $count 每页多少条数据 * $page 当前第几页 * $array 查询出来的所有数组 * order 0 - 不变 1- 反序 */ public function page_array($count,$page,$array,$order){ global $countpage; #定全局变量 $page=(empty($page))?'1':$page; #判断当前页面是否为空 如果为空就表示为第一页面 $start=($page-1)*$count; #计算每次分页的开始位置 if($order==1){ $array=array_reverse($array); } $totals=count($array); $countpage=ceil($totals/$count); #计算总页面数 $pagedata=array(); $pagedata=array_slice($array,$start,$count); return $pagedata; #返回查询数据 }