获取所有记录(带查询条件、分页)
//获取所有记录
public function table() {
if (isset($_GET['reservation_type'])) {
$map['reservation_type'] = $_GET['reservation_type'];
}
if (isset($_GET['keyword'])) {
$where['name'] = array('like', '%' . $_GET['keyword'] . '%');
$where['phone'] = array('like', '%' . $_GET['keyword'] . '%');
$where['store'] = array('like', '%' . $_GET['keyword'] . '%');
$where['receiver'] = array('like', '%' . $_GET['keyword'] . '%');
$where['_logic'] = 'or';
$map['_complex'] = $where;
}
$reservation = M('customer_reservation_record');
$count = $reservation->where($map)->count(); // 查询满足要求的总记录数
$Page = new \Think\Page($count, 10); // 实例化分页类 传入总记录数和每页显示的记录数(25)
$show = $Page->show(); // 分页显示输出
// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
$limit = $Page->firstRow . ',' . $Page->listRows;
$sort = "crr_id desc";
$list = $reservation->where($map)->limit($limit)->order($sort)->select();
$this->assign('list', $list); // 赋值数据集
$this->assign('page', $show); // 赋值分页输出
$this->display(); // 输出模板
}