ianace
ianace

Reputation: 1635

MYSQL Count all rows and pagination of data using range/limit

I dont know if this is a duplicate but here's my question..

I was trying to implement a pagination of data taken from database

My dilemma is:

  1. Should i go about pagination, querying data in groups, ie. 5 (doing a Select with limits/ range), then displaying them in a table with pagination. It will have page numbers so it would require counting all the table entries thus that would be 2 database queries for the initial display.or

  2. query all the row entries and then count the result set and apply pagination. This would remove the query count on the database but would also mean that i would download the whole data everytime a single view on any page is made (but i could also apply caching)

and other suggestions are highly accepted and thank you in advance

Upvotes: 3

Views: 6033

Answers (1)

Wesley van Opdorp
Wesley van Opdorp

Reputation: 14941

SQL_CALC_FOUND_ROWS .

This will allow you to use LIMIT and have the amount of rows as no limit was used.

Upvotes: 7

Related Questions