分页技术
是一种将所有数据分段展示给用户的技术.用户每次看到的不是全部数据,而是其中的一部分,如果在其中没有找到自习自己想要的内容,用户可以通过制定页码或是翻页的方式转换可见内容,直到找到自己想要的内容为止。
前10条记录:
select * from table limit 0,10
第11至20条记录:
select * from table limit 10,10
第21至30条记录:
select * from table limit 20,10
从上面可以看出规律
(当前页数 - 1 )X 每页条数 , 每页条数
Select * from table limit ($Page- 1) * $PageSize, $PageSize
上代码
控制器部分
public function getlists(Request $request) {
// 获取到当前currentpage 和perpage 每页多少条
$currentPage = (int)$request->input('current_page');
$perage = (int)$request->input('perpage');
$limitprame = ($currentPage -1) * $perage;
$info = DB::table('user_info')-> skip($limitprame)->take($perage)-> get();