thinkphp分页

Controller:

 

<?php
namespace Home\Controller;
use Think\Controller;
header("Content-Type:text/html;charset=utf8");
class IndexController extends Controller {
    public function index() {
        $m = M('user');//实例化数据库
        $where = "id>0";
        $count = $m->where($where)->count();//满足条件总数
        $p = getpage($count);//调函数
        //进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $list = $m->field(true)->where($where)->order('id')->limit($p->firstRow, $p->listRows)->select();
        $this->assign('select', $list); // 赋值数据集
//        var_dump($list['id']);die();
        $this->assign('page', $p->show()); // 赋值分页输出
//        echo $list;die();
        $this->display();
    }
}

 

function:

 

<?php
function getpage($count,$pagesize) {
    $p = new Think\Page($count,2);
    //setConfig分页样式定制
    $p->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
    $p->setConfig('prev', '上一页');
    $p->setConfig('next', '下一页');
    $p->setConfig('last', '末页');
    $p->setConfig('first', '首页');
    $p->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
    $p->lastSuffix = false;//最后一页不显示为总页数
    return $p;
}
?>

 

html页面:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>用户信息输出</title>
   <style type="text/css">
      .pages a,.pages span {
         display:inline-block;
         padding:2px 5px;
         margin:0 1px;
         border:1px solid #f0f0f0;
         -webkit-border-radius:3px;
         -moz-border-radius:3px;
         border-radius:3px;
      }
      .pages a,.pages li {
         display:inline-block;
         list-style: none;
         text-decoration:none; color:#58A0D3;
      }
      .pages a.first,.pages a.prev,.pages a.next,.pages a.end{
         margin:0;
      }
      .pages a:hover{
         border-color:#50A8E6;
      }
      .pages span.current{
         background:#50A8E6;
         color:#FFF;
         font-weight:700;
         border-color:#50A8E6;
      }
   </style>
</head>

<body>
<table width="405" border="1" cellpadding="1" cellspacing="1" bgcolor="#99CC33" bordercolor="#FFFFFF">
   <tr>
      <td colspan="3" bgcolor="#FFFFFF" class="title" align="center">用户信息</td>
   </tr>
   <tr class="title">
      <td bgcolor="#FFFFFF" width="44">ID</td>
      <td bgcolor="#FFFFFF" width="120">用户名</td>
      <td bgcolor="#FFFFFF" width="223">密码</td>
   </tr>
   <foreach name='select' item='user' >
      <tr class="content">
         <td bgcolor="#FFFFFF">&nbsp;{$user.id}</td>
         <td bgcolor="#FFFFFF">&nbsp;{$user.account}</td>
         <td bgcolor="#FFFFFF">&nbsp;{$user.pwd}</td>
      </tr>
   </foreach>
   <tr class="content">
      <!--<td colspan="3" bgcolor="#FFFFFF">&nbsp;{$page}</td>-->
      <td colspan="3" bgcolor="#FFFFFF"><div class="pages">
         {$page}
      </div></td>
   </tr>
</table>
</body>
</html>

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值