title: Implementing PHP Pagination for a SQLite query set
body: <p>I'm looking for a good function for implementing pagination in a PHP site. The solution needs to work for vanilla PHP (no template language, no frameworks, etc). I'd like to be able to put something like the following in my code:</p>
  
  <pre><code>&lt;? $widgets = ... (some query)?&gt;
  Page content here.
  &lt;?= paginate($widgets) ?&gt;
  </code></pre>
  
  <p>This would output something like the following:</p>
  
  <pre><code>Page content here.
  1 &lt;a href='?page=2'&gt;2&lt;/a&gt; &lt;a href='?page=3'&gt;3&lt;/a&gt; . . . 
  </code></pre>
  
  <p>Then, there is the issue of filtering my query. I could query twice, once to get a count of total objects and once with a limit clause to get the specific "widgets" that I need.</p>
  
  <p>Are there any simple PHP functions that can elegantly encapsulate this functionality, or is it something best done by hand? I think I've become spoiled by <a href="http://eflorenzano.com/blog/post/first-two-django-screencasts/#using-django-pagination" rel="nofollow noreferrer">django-pagination</a>, but this project requires a PHP solution.</p>