简体   繁体   English

使用LIMIT 0、20进行无限滚动-如何限制总结果数?

[英]using LIMIT 0, 20 for infinite scroll - how to limit the number of total results?

I have a query: 我有一个查询:

 select * from table where id is not null order by desc LIMIT :start, :limit

the start and limit are there for the ajax infinite scroll / pagination to work ajax无限滚动/分页工作的开始和极限

How can I limit the total results if im using limit already for the pagination? 如果即时通讯已经使用limit来限制总结果?

I need a query similar to below: 我需要类似以下的查询:

select * from table where id is not null order by desc LIMIT :start, :limit LIMIT 5000

You can calculate this without the query. 您可以在不查询的情况下进行计算。 If you don't want more than 5000 results, this should work: 如果您不希望获得超过5000个结果,则应该可以使用:

if (($start + $limit) <= 5000) {
    // Do query
}
else {
    // Don't do query, maximum limit reached
}

You can create a view in your database wih the following syntax: 您可以使用以下语法在数据库中创建视图:

create view view_name as select * from table where id is not null order by desc LIMIT 5000

Then you will query the view for the ajax infinite scroll / pagination 然后您将在视图中查询ajax无限滚动/分页

select * from view_name where id is not null order by desc LIMIT :start, :limit

Note: with the view your can use a simpler query, since the view already choose the good rows (with non null id), and order them. 注意:使用该视图,您可以使用一个更简单的查询,因为该视图已经选择了好行(具有非null ID)并对其进行了排序。

select * from view_name LIMIT :start, :limit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM