public function dark_house() {
if ($_POST) {
} else{
$store_id = $_SESSION["admin"]["store_id"];
// 加入搜索功能
$get = I("get.");
$member_type = $get["pub"];
$name = $get["name"];
if ($member_type) {
if ($member_type == 1) {
$map["limit_time_end"] = array("neq", 0);
} elseif ($member_type == 2) {
$map["limit_time_end"] = array("eq", 0);
}
}
if ($name) {
$map["truename|login_account"] = array("like", "%".$name."%");
}
$this->assign("search", $name);
$this->assign("v", $member_type);
$map["store_id"] = array("eq", $store_id);
$map["is_disabled"] = array("eq", 1);
$map["is_member"] = array("eq", 1);
$count = M("member")->where($map)->count(); // 获取总记录的条数,进行分页
$page = $this->getpage($count,20); // 实例化分页类,传入总条数以及每页的列数
$show = $page->show(); // 分页显示输出
$list = M("member")->where($map)->field("member_id, login_account, truename, sex, limit_time_end")->limit($page->firstRow.','.$page->listRows)->select();
foreach ($list as $k => $v) {
if ($v["limit_time_end"] == 0) {
$list[$k]["operation"] = "惩罚";
$list[$k]["punishment"] = "punishment";
$list[$k]["limit_time_end"] = "不惩罚";
} else {
$list[$k]["operation"] = "解除";
$list[$k]["punishment"] = "relieve";
$list[$k]["limit_time_end"] = date("Y-m-d",$v["limit_time_end"]);
$list[$k]["disabled"] = "disabled";
}
// 统计会员的旷课次数
$member_id = $list[$k]["member_id"];
$cmap["store_id"] = $store_id;
$cmap["member_id"] = $member_id;
$cmap["is_sign"] = 0;
$countC = M("reservation")->where($cmap)->count();
//echo M("reservation")->getLastSql();exit;
$list[$k]["count"] = $countC;
}
$this->assign('list',$list);// 赋值数据集
$this->assign('page',$show);// 赋值分页输出
$this->display(); // 输出模板
}
}
// 分页样式
public function getpage($count, $pagesize = 10) {
$p = new \Think\Page($count, $pagesize);
$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;
}
重点阐述;
1.需要引入thinkphp的分页类 \Think\Page()
2.传入总页码,以及每页的条数。
3.将page对象以及数组对象传入页面中。
<style>
.punishment {
background: #ff2c7b;
}
.relieve{
background: #00ab23;
}
.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;
}
.pages{
margin-bottom: 100px;
}
</style>
<form action="" method="get">
<select name="pub" id="punb">
<option <if condition="$v eq 0">selected</if> value="0">全部会员</option>
<option <if condition="$v eq 1">selected</if> value="1">惩罚的会员</option>
<option <if condition="$v eq 2">selected</if> value="2">未惩罚的会员</option>
</select>
<input type="text" placeholder="会员名或手机号" name="name" value="{$search}">
<input type="hidden" name="p" value="1">
<button>搜索</button>
</form>
<div class="pages">{$page}</div>
重点阐述:
1.分页的样式thinkphp已经帮你渲染好。
2.所以仅仅需要重写样式即可。
3.条件搜索的时候记住加上`<input type="hidden" name="p" value="1">`它是为了重置页码。
4.