微擎后台数据分页

前端页面 直接一个变量 {$pager} 放到最后的位置,自动生成分页



//定义页码
$pindex = max(1, intval($_GPC['page']));
//定义记录数
$psize = 30;
//排序与每页多少条记录
$limit = " ORDER BY id DESC LIMIT " . ($pindex -1) * $psize . ", {$psize}";
//数据查询条件
$where = ' WHERE uniacid = :uniacid AND type = 1';
//对应公众号id
$param = array(':uniacid' => $_W['uniacid']);
//根据前面定义的条件查询出总记录数
$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('duson_zzbd_sham') . " {$where}", $param);
//数据数组
$notices = pdo_fetchall('SELECT * FROM ' . tablename('duson_zzbd_sham') . " {$where} {$limit}", $param);
//分页按钮
$pager = pagination($total, $pindex, $psize);


if(!empty($_GPC['nickname'])) {
     $uniacid = $_W['uniacid'] ;
     $where = ' WHERE uniacid=:uniacid  and  nickname like "%'.$_GPC['nickname'].'%"';
     $param = array(':uniacid' => $_W['uniacid']);
}else{
    //数据查询条件
    $where = ' WHERE uniacid = :uniacid' ;
//对应公众号id
    $param = array(':uniacid' => $_W['uniacid']);
}


//定义页码
$pindex = max(1, intval($_GPC['page']));
//定义记录数
$psize = 30;
//排序与每页多少条记录
$limit = " ORDER BY id DESC LIMIT " . ($pindex -1) * $psize . ", {$psize}";

//根据前面定义的条件查询出总记录数
$total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('xiaoka_user') . " {$where}", $param);
//数据数组
$list = pdo_fetchall('SELECT * FROM ' . tablename('xiaoka_user') . " {$where} {$limit}", $param);
//分页按钮
$pager = pagination($total, $pindex, $psize);

你可能感兴趣的:(php)