Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetch Data and check if has "Next Page" in One Query?

Is there any way to check if any rows left for the next LIMIT query (for showing Next Page link)? I don't want COUNT(), extra SELECT, etc I use Limit a,b for getting each pages's posts.

Thanks!

like image 964
Positivity Avatar asked Sep 18 '25 00:09

Positivity


1 Answers

You can use LIMIT N+1 in your query (where N is the actual limit). If the query returns N+1 rows, there are further pages; otherwise, you're on the last page. Of course this will require adjustments in other parts of your code, to omit the last row from the results displayed.

like image 59
bfavaretto Avatar answered Sep 20 '25 15:09

bfavaretto