php bootstrap 分页 查询,一例基于thinkphp,jquery和bootstrap渲染的查询数据分页器

对于某些查询记录很多的结果,web页面不得不采用分页器,现在奉上一例代码,其主要逻辑是:由页面的dom

节点发起ajax请求,返回的查询结果根据页面布局需要进行切片;并根据总记录数和页面展现的条数算出页码列表

html部分

分页技术测试

Navbar

Bootstrap starter template


  • 共计:当前第

thinkphp部分

use think\mongo\Query;

class Goodmaster extends Controller

{

function forpagination($tblname,$numperpage,$start,$end,$current)

{

$ret = Db::connect('db_mongo')->name($tblname)->select();

$resultlist=Array();

$totalnum = count($ret);//总记录数

$current=intval($current);

$numperpage =intval($numperpage);

//总页数=总记录数/每页面显示的条数

//关于页数分两种情况:1.总记录数大于每页显示的条数使用上述公式

//2.总记录数小于每页显示的条数,$totalpage = 1

if($totalnum

{

$totalpage=1;

$startpage = 1;

$endpage = 1;

$resultlist['ret'] =$ret;

}

else{

$totalpage = ceil($totalnum/$numperpage);

$startpage = $start;

$endpage = $end;

$leftindex =($current-1)*$numperpage;//数组切片左索引

$rightindex =$leftindex+$numperpage;//数组切片左索引

$subret = array_slice($ret,$leftindex,$numperpage);

$resultlist['ret'] =$subret;

}

$resultlist['totalpage'] =$totalpage;

$resultlist['frompage'] =$startpage;

$resultlist['current'] =$current;

$resultlist['topage'] =$endpage;

$resultlist['leftindex'] =$leftindex;

$resultlist['totalnum'] =$totalnum;

//return var_dump($resultlist);

return $resultlist;

}

}

thinkphp5.11查询功能 代码,牛逼的朋友请自行去粗取精

标签:jquery,记录,bootstrap,查询,current,条数,thinkphp,numperpage,页面

来源: https://www.cnblogs.com/saintdingspage/p/10398362.html

你可能感兴趣的:(php,bootstrap,分页,查询)