thinkphp实现数据分页
方法一:
1 public function show_cate(){ 2 3 $category_name = array( 4 '1' => '政法综治前沿', 5 '2' => '政策法规', 6 '3' => '平安建设', 7 '4' => '通知公告', 8 '5' => '理论研讨', 9 '6' => '本地动态', 10 '7' => '队伍建设', 11 ); 12 $category_id = I('get.category_id'); 13 $model = M('zx_article'); 14 //计算要显示的总数据条数 15 $count = $model->where('category_id ='.$category_id)->order('article_id desc')->count(); 16 //实例化Page类,传入总条数和每页要显示的条数 17 $page = new \Think\Page($count,2); 18 //使用limit函数指定查询和操作的数量 19 $data = $model->where('category_id ='.$category_id)->order('article_id desc')->limit($page->firstRow.','.$page->listRows)->select(); 20 //传数据给模板 21 $this->assign('data',$data); 22 //调用Page类的show()函数
23 $this->assign('page',$page->show()); 24 $this->assign('name',$category_name[$category_id]); 25 $this->display(); 26 }