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:
<? $widgets = ... (some query)?>
Page content here.
<?= paginate($widgets) ?>
This would output something like the following:
Page content here.
1 <a href='?page=2'>2</a> <a href='?page=3'>3</a> . . .
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.
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 django-pagination, but this project requires a PHP solution.