数组分页,参考网址
https://blog.csdn.net/L_Taozi/article/details/89673256
分页样式,参考网址
https://blog.csdn.net/qq_16030133/article/details/70783898
以上,非常好用
分页代码
注意引入
use think\paginator\driver\Bootstrap;
$listt = Db::connect('database.db_config2')->table('red_ckgs')->where('fenlei',$id)->where('status',1)->order("id DESC")->select();
$list = [];
foreach($listt as $v){
$h = Db::connect('database.db_config2')->table('red_users')->where('id',$v['userid'])->find();
$v['username'] = $h['user_login'];
$pic = explode(',',$v['tiezipicture']);
$v['pic'] = 'http://www.h.com/data/upload/'.$pic['0'];
$list[] = $v;
}
// 下面是对数组进行分页
$curpage = input('page') ? input('page') : 1;//当前第x页,有效值为:1,2,3,4,5...
$listRow = 2; //每页10行记录
$dataTo=array();
$dataTo=array_chunk($list,$listRow);
$showdata=array();
if($dataTo){
$showdata = $dataTo[$curpage-1];
}else{
$showdata=null;
}
$p = Bootstrap::make($showdata, $listRow, $curpage, count($list), false, [
'var_page' => 'page',
'path' => url('/home/ckgs/ck_list'),//这里根据需要修改url
'query' => Request::instance()->param(),//此处参数可以保留当前数据集的查询条件
'fragment' => '',
]);
$this->assign('list',$p);
$this->assign('plistpage', $p->render());
return $this->fetch('ckgs/list');
html 页面中
<style type="text/css">
/*分页样式*/
.pagination{text-align:center;margin-top:20px;margin-bottom: 20px;}
.pagination li{margin:0px 10px; border:1px solid #e6e6e6;padding: 3px 8px;display: inline-block;}
.pagination .active{background-color: #dd1a20;color: #fff;}
.pagination .disabled{color:#aaa;}
</style>
<div data-tab-panel-0 class="am-tab-panel am-active">
<ul class=" solutions-content-ul">
{foreach $list as $v}
<li class="am-u-sm-12 am-u-md-6 am-u-lg-12">
<a href="{:url('home/ckgs/detail', ['id' => $v.id])}">
<div class="am-u-sm-12 am-u-md-12 am-u-lg-3 solution-tabs-img">
<img src="{$v.pic}" />
</div>
<div class="am-u-sm-12 am-u-md-12 am-u-lg-9 solution-tabs-words">
<p>{$v.username}</p>
<h5>{$v.title}</h5>
</div>
</a>
</li>
{/foreach}
</ul>
<div class="pagination">
{$plistpage}
</div>
</div>