当前位置:首页 > CMS教程 > Thinkphp > 列表

thinkPHP中分页用法实例分析

发布:smiling 来源: PHP粉丝网  添加日期:2021-07-02 10:29:55 浏览: 评论:0 

这篇文章主要介绍了thinkPHP中分页用法,结合实例形式详细分析了thinkPHP数据查询及使用分页类实现分页效果的相关技巧,需要的朋友可以参考下。

本文实例讲述了thinkPHP中分页用法,分享给大家供大家参考,具体如下:

拿一个实例来说吧

action页面:

  1. public function show(){ 
  2.    import("ORG.Util.Page"); //导入分页类 
  3.    $news=D("News"); 
  4.    $count = $news->where('`content_type`='.$id)->count(); //查询记录的总条数 
  5.    $p = new Page($count, 10); 
  6.    $list = $contact->where('`content_type`='.$id)->order('sort')->limit($p->firstRow . ',' . $p->listRows)->select();  
  7.    $p->setConfig('header', '条数据'); //分页样式可自定义 
  8.    $p->setConfig('prev', "<");  
  9.    $p->setConfig('next', '>');  
  10.    $p->setConfig('first', '<<');  
  11.    $p->setConfig('last', '>>');  
  12.    $page = $p->show(); //分页的导航条的输出变量 
  13.    $this->assign("page",$page); //在模板页面中输出分页 
  14.    $this->assign('info',$list); //查询的信息反馈到模板页面中 
  15.    $this->display('index'); 
  16. } 

调用的tpl页面:index.php

自定义的css样式,主要用于分页样式

  1. <style type="text/css"> 
  2. .page{ 
  3.  font-size:18px; 
  4. } 
  5. .page .current{ 
  6.  width:10px; 
  7.  font-size:16px; 
  8.  margin-left:5px; 
  9.  padding:2px; 
  10.  border:1px solid #000; 
  11. } 
  12. .page a{ 
  13.  min-width:10px; 
  14.  font-size:16px; 
  15.  margin-left:5px; 
  16.  border:1px solid #000; 
  17.  padding:2px; 
  18. } 
  19. </style> 

循环输出分页信息

  1. 1 
  2. 2 
  3. 3 
  4. 4 
  5. ................ 
  6. ............... 
  7. ............... 
  8. <div class="page"> {$page} </page> <!-- 输出分页信息 -->

Tags: thinkPHP分页

分享到: