4

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!

Positivity
  • 5,406
  • 6
  • 41
  • 61
  • Check the total number of rows with `SQL_CALC_FOUND_ROWS` http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows – Tchoupi Aug 26 '13 at 02:26
  • @MathieuImbert and then? check last fetched row's id whit this? – Positivity Aug 26 '13 at 02:41

1 Answers1

6

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.

bfavaretto
  • 71,580
  • 16
  • 111
  • 150
  • Thanks, the only negative point is the extra logic I should add for getting maximum N rows out of the N+1 that this query returns. – Positivity Aug 26 '13 at 02:37