public function index(){
if(IS_POST){
$k = I('keyword');
$keyword = '%'.$k.'%';
$map['name|sex|tel|company|comment'] = array('like',$keyword);
$customer = M('customer');
//分页
$mapcount = $customer->where($map)->count();// 查询满足要求的总记录数
$Page = new \Think\Page($mapcount,1);// 实例化分页类 传入总记录数和每页显示的记录数
//分页跳转的时候保证查询条件
foreach($map as $key=>$val) {
$Page->parameter .= "$key=".urlencode($val).'&';
}
$show = $Page->show();// 分页显示输出
$cs = $customer->limit($Page->firstRow.','.$Page->listRows)->where($map)->select();
$this->assign('page',$show);// 赋值分页输出
$this->assign('customers',$cs);
$this->assign('keyword',$k);
$this->display();
return;
}
$customer = M('customer');
//分页
$count = $customer->count();// 查询满足要求的总记录数
$Page = new \Think\Page($count,2);// 实例化分页类 传入总记录数和每页显示的记录数(25)
$show = $Page->show();// 分页显示输出
$cs = $customer->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('page',$show);// 赋值分页输出
$this->assign('customers',$cs);
$this->display();
}
最佳答案