thinkphp中对数组元素进展分页显示
程序员文章站
2024-02-19 18:19:52
...
thinkphp中对数组元素进行分页显示
PHP模块代码:class NewsAction extends Action{public $page = ''; //分页,当前页数 function News(){ $list = M("News")->field('id,title')->where("status = 5")->findAll(); //分页 $list = $this->array_page($list); //结束 $num = 0; $URL = "http://www.baidu.com/"; $suffixName = '.html'; foreach($list as $key=>$val){ $num = $key + 1; $str .= ' '.$num.").".$val['title']."
"; } $str = preg_replace('/(.*),\s$/','\\1',$str); $str .= "".$this->page.""; return $str; } //数组分页方法 /** * array $array 数组 * integer $showCount 每页的记录数 *------------------------------ * return array 返回数组 */ function array_page($array,$listRows = 12,$showCount = 4){ $p = C('VAR_PAGE'); $url = $_SERVER['REQUEST_URI']."/".$p."/"; $page = !empty($_GET[C('VAR_PAGE')])?$_GET[C('VAR_PAGE')]:1; $upRow = $page-1; $downRow = $page+1; $linkPage = ""; $totalPage = (int)count($array); $pagetotal = ceil($totalPage/$listRows); //总页数 if($page = $pagetotal) $maxpg = $pagetotal + 1; }elseif($page > ceil(($showCount)/2) && $page = $pagetotal) $maxpg = $pagetotal; }elseif($page >=$pagetotal - ceil(($showCount)/2)){ $minpg = $pagetotal - ($showCount-1); if($minpg == 1) $minpg = 2; $maxpg = $pagetotal + 1; } $linkPage .= " ".$totalPage." 条记录 ".$page."/".$pagetotal." 页 "; if($pagetotal == 1){ $linkPage .= " 1 "; }else{ if($page > 1){ $linkPage .= " 第一页"; $linkPage .= " 上一页"; } for($i = $minpg; $i ". $i ."
上一篇: php读取mysql数据库中的html数据代码,如何读取
下一篇: 加密你的Access数据库