/** * @Purpose:对数组分页的方法 * @param int $pagenow 当前页 * @param int $pagerec 每页显示的记录数 * @paran array $array 分页数组 */ public function pagesphp($pagenow, $pagerec, $array) { if (empty($array)) { return ''; } else { if ($pagenow == '' || $pagenow == 1) { $pagenow = 1; } $total_user = count($array); //总记录数 $pages = ceil($total_user / $pagerec); //总页数 if ($pagenow > $pages) { $pagenow = $pages; } if ($pagenow <= 1) { $beforepage = 1; if ($pages > 1) { $afterpage = $pagenow + 1; } else { $afterpage = 1; } } else { $beforepage = $pagenow - 1; if ($pagenow < $pages) { $afterpage = $pagenow + 1; } else { $afterpage = $pages; } } $fenyeshuzu['data'] = array_slice($array, ($pagenow - 1) * $pagerec, $pagerec); $fenyeshuzu['info']['pbefore'] = $beforepage; $fenyeshuzu['info']['pafter'] = $afterpage; $fenyeshuzu['info']['pagenow'] = $pagenow; $fenyeshuzu['info']['headpage'] = 1; $fenyeshuzu['info']['pages'] = $pages; $fenyeshuzu['info']['total_user'] = $total_user; return $fenyeshuzu; } }
//调用pagesphp函数 public function getdata($date,$pagenow,$rowsperpage){ if ($date == ''){ $sql = "select * from esni"; }else{ $sql = "select * from esni where year='{$date}' "; } // echo $sql; $data = $this->dataarrayold($sql); $datainfo = $this->pagesphp($pagenow, $rowsperpage, $data); return $datainfo; } //定义pagenow并调用getdata函数 if(empty($pagenow)){ $pagenow = 1; } $getesni = $zhishu->getdata($date,$pagenow,12);
html页面