Critique my pagination class
Posted: Tue Dec 21, 2010 1:17 am
Hello,
This is a pagination class that i created and I am looking for feedback on it. I created it because pagination comes up often when i work for clients and having to constantly copy functions and amend them is becoming tedious. This class displays the paginated results from a database in a tabular form with navigation just below that.
When i created it i thought about implementing it without having the user (of the script) enter database information like username, password etc. It should be easy to incorporate into an existing system and use existing resources. The constructor accepts the arguments needed for the script to work in the following order:
1. A mysqli link identifier
2. An array with field names
3. A name of a page where the pagination will be displayed (sans an extension)
4. Table name
5. Count column (Prefrably a PK that is auto_increment)
6. The amount of items per page
Because the script uses an existing connection I suppressed all the SQL errors but if they should occur a notification message will be issued along with the mysqli_error() explanation (if any). Database connection errors in this instance is the responsibilitty of the person using the script and not of the script itself (another pluspoint IMO).
If you do test the script (a pre-emptive Thank you is in order) i'd welcome the following feedback:
Q1. Is it easy to use? I would like newbies to also use this but it might contain code that is more within the grasp of intermediate users.
Q2. How can you break it? Things like "I entered an invalid table name" or "I injected some additional sql code.." would be helpful.
Q3. How can it be improved? My goal wasn't to create the silver bullet for pagination but instead a class that can be easily implemented with minimal effort and something that would solve a common problem for many users.
I tested the script on a XAMPP server running PHP 5.2.5 and MySQL server version 3.23.32.
This is a pagination class that i created and I am looking for feedback on it. I created it because pagination comes up often when i work for clients and having to constantly copy functions and amend them is becoming tedious. This class displays the paginated results from a database in a tabular form with navigation just below that.
When i created it i thought about implementing it without having the user (of the script) enter database information like username, password etc. It should be easy to incorporate into an existing system and use existing resources. The constructor accepts the arguments needed for the script to work in the following order:
1. A mysqli link identifier
2. An array with field names
3. A name of a page where the pagination will be displayed (sans an extension)
4. Table name
5. Count column (Prefrably a PK that is auto_increment)
6. The amount of items per page
Because the script uses an existing connection I suppressed all the SQL errors but if they should occur a notification message will be issued along with the mysqli_error() explanation (if any). Database connection errors in this instance is the responsibilitty of the person using the script and not of the script itself (another pluspoint IMO).
If you do test the script (a pre-emptive Thank you is in order) i'd welcome the following feedback:
Q1. Is it easy to use? I would like newbies to also use this but it might contain code that is more within the grasp of intermediate users.
Q2. How can you break it? Things like "I entered an invalid table name" or "I injected some additional sql code.." would be helpful.
Q3. How can it be improved? My goal wasn't to create the silver bullet for pagination but instead a class that can be easily implemented with minimal effort and something that would solve a common problem for many users.
I tested the script on a XAMPP server running PHP 5.2.5 and MySQL server version 3.23.32.