Notice: This is a discussion thread for comments about the SitePoint article, Perfect PHP Pagination.
Where’s the code download?
End of “Required Files” section says “(link to code download)” but doesn’t actually display a link to the code download
It would been nice to see this strategy applied to some a little more complex than arrays to something like database queries. The Paginated class requires that you pre-fetch the data into an array which puts needless performance overhead on your script/server. Generally speaking, the 3 primary needs for pagination are arrays, file systems and database results.
You’ve gone to lengths to separate the page layout from the data, but haven’t bothered abstracting the data source for some reason.
the link is good.I have tried it and I am getting the result with success
But if I am having query string in my url so is there any way to build the query string of url in the class itself?
I always envisaged pagination as a decorator actually. It acts very much like a filter (which in java is modelled as a decorator). So you’re filtering results down to a smaller set based on a couple of parameters. It would also follow true that filtering by first letter would again be a filter which would act on your original object.
I am querying one of my tables for two values and its only displaying the first value of the first row and there are 23 rows returned by the query. Can you give an example of how to alter your script to use a query?
Well I don’t want to get some poeple upset here but I guess this (and the named PEAR class too) is not really what should be considered to be perfect for a pagination class. Its all still too rendering related what the classes do.
If you don’t have a problem with mixin’ business logic and render stuff it should be fine though I suppose.
Otherwise one would opt for a more separated approach that is just in charge of generating some pagination urls and/or page numbers for the pagination instead of being in charge of rendering the whole list of records too.
This way everything is just more loosely coupled.
This whole thing might look nice, but it’s unneccessarily complicating things for something as simple as pagination.
Apart from that it’s not practicable! You have to pass the whole result set to the class to get the pagination done… That might work with a list of 20 names, but definitely NOT with hundreds or thousands of database entries of any kind.
It wastes not only memory but also cpu power loading ALL the results, where you only need a piece.
@raduku
i’m getting this error when i use the code below
Fatal error: Class ‘PaginatedMysqlResultSet’ not found in /home/.mysite/example.com/index.php on line 98
After session_start() in index.php put this lines in this order
require_once ‘Paginated.php’;
require_once ‘PaginatedResultSet.php’;
require_once ‘PaginatedMysqlResultSet.php’;
require_once ‘PageLayout.php’;
require_once ‘DoubleBarLayout.php’;
if this files are in the same directory as index.php, if there are not make sure the path (relative or absolute) is correct.