Closed rrickgauer closed 3 years ago
Pagination includes the URL parameters:
page
per_page
To implement this, I'll need to utilize MySQL's LIMIT and OFFSET commands.
Limit is simple to calculate. It is equal to the value provided in the per_page
url parameter.
Offset is a little more complicated. Since MySQL is 0-based index, this is how to calculate the offset:
OFFSET = (page - 1) * per_page
OFFSET = (3 - 1) * 20
OFFSET = 2 * 20
OFFSET = 40
Then the resulting MySQL statement would look like:
SELECT * FROM table_name LIMIT 20 OFFSET 40;
For search products, have a default per_page
of 20 and a max of 50
Need to add pagination to any resource that returns more than 1 object in its response.