Trying to teach myself the concept of how to calculate the indexes for pagination, I have found the following text:
Say for example that we have per page equals to 10, so it will be ten items per page. Once again our calculation for offset is per page, which is ten, times the current page, minus 1. If the current page is 1, that calculation works out so that offset is 0, and that would mean that records 1 through 10 would be 10, and that would mean that records 11 through 20 would be returned
Maybe I'm looking at it the wrong way, but I don't get it.
The text states that using an example of 10 items per page, and we're on the first page, the formula should be:
10 * 1 - 1 -> this by my brain cramp should equal 9, but the text says it's 0
The next example they use is: 10 * 2 - 1 = 10, using normal math, is that not 19??
there's obviously something I'm missing here.
What they mean is
10 * (1-1) = 0
and
10 * (2-1) = 10
In the end this boils down to the fact that people count from 1 (the first page is page 1), but the offset starts at 0. So if you have a page-number, you need to lower it by one to get the offset number (the first page is 1, the first offset is 0 ).
THat means you first subtract (hence the brackets) and then multiply. The text is just a little bit confusing.