title: How do I calculate the offsets for pagination?
body: <p>I am working on a pagination feature in a web service I am writing, but my lack of math insight is killing me now.
  I have a couple of keys: <code>totalItems</code>, <code>currentItems</code>, <code>currentPage</code>, <code>totalPages</code>, but also a couple of links to <code>first</code>, <code>last</code>, <code>previous</code> and <code>next</code>.</p>
  
  <p>At this moment, I am doing the following calculations:</p>
  
  <ul>
  <li><code>totalItems</code>: number of rows in the table</li>
  <li><code>currentItems</code>: <code>limit</code> parameter from HTTP request</li>
  <li><code>currentPage</code>: <code>start</code> parameter divided by <code>limit</code> parameter</li>
  <li><code>totalPages</code>: number of rows in the table divided by <code>limit</code>. (Rounded up, 8.1 page = 9 pages)</li>
  </ul>
  
  <p>I assume those calculations to be correct, what I <strong>am</strong> struggling with is the following:</p>
  
  <ul>
  <li><code>first</code>: <code>start</code> parameter is 1 with <code>limit</code> from the HTTP request</li>
  <li><code>last</code>: should be the first item of the last page, how do I calculate this correctly?</li>
  <li><code>previous</code>: should be the first item of the previous page, how do I do this?</li>
  <li><code>next</code>: should be the first item of the next page, how do I do this?</li>
  </ul>
  
  <p>What I would like to ask, is: are my calculations correct? And how do I tackle the three problems with <code>last</code>, <code>previous</code> and <code>next</code>?</p>