title: PHP blog pagination difficulty (working out number of page containing specific post)
body: <p>I'm creating a simple PHP blog script, and I need to work out which page a particular post will be on, but can't work out how to do it myself; I suppose it's a little bit more of a maths question than a strictly PHP one. I've included some potentially useful variables (their names are descriptive) in the function below, but I don't know what calculation I can return. If, for example, the blog contains 12 posts (so $numberOfPosts === 12) and $postsPerPage is set to 5, page one will contain posts 12-8 (i.e. the most recent ones), page two will contain posts 7-3, whilst page three will contain posts 2 &amp; 1 (the variable $postsOnLastPage in this case will equal two, and $numberOfPages will equal 3). Of course, I need a function that can work with these variables regardless of their value (well, all positive integers of course and not necessarily all of them, just all that are needed to get the correct return value). With all of that having been said, I really hope some bright spark will be able to work this out for me.</p>
  
  <pre><code>function whichPage($postNumber) {
      global $numberOfPages, $numberOfPosts, $postsPerPage, $postsOnLastPage;
      if ($postNumber &gt; $numberOfPosts || $postNumber &lt;= 0) return false;
      return ???????;
  };
  </code></pre>
  
  <p>Much appreciated.</p>