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>条记录 第<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"> {$user.id}</td>
<td bgcolor="#FFFFFF"> {$user.account}</td>
<td bgcolor="#FFFFFF"> {$user.pwd}</td>
</tr>
</foreach>
<tr class="content">
<!--<td colspan="3" bgcolor="#FFFFFF"> {$page}</td>-->
<td colspan="3" bgcolor="#FFFFFF"><div class="pages">
{$page}
</div></td>
</tr>
</table>
</body>
</html>