php 使用分页获取结果总数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28466286/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get total number of results with pagination
提问by PeterInvincible
I'd like to get the total number of users on a page where all the users are listed. This page should be paginated.
我想在列出所有用户的页面上获取用户总数。这个页面应该分页。
So far, this is what I've come up with:
到目前为止,这就是我想出的:
Controller
控制器
$users = User::paginate(10);
return View::make('index', compact('users'));
View:
看法:
{{{ count($users) }}}
But this gives me only the count of the users for the current page. I'd like to count the full result set, if possible without querying another time the database.
但这只给了我当前页面的用户数。如果可能,我想计算完整的结果集,而无需再次查询数据库。
回答by lukasgeiter
回答by Sunil kumawat
Controller
控制器
$products = ProductMaster::paginate(10); //1 page with 10 products
return view('index',compact('products'));
view
看法
{{ $products->total() }} //show total products in your database