PaginateIt Overview - A PHP Pagination Class

Author: Brady Vercher
Version: 2.0
Website: http://www.blazersix.com/

Table of Contents

Frequently Asked Questions

What is PaginateIt?

PaginateIt is a simple PHP class I wrote to make pagination easy. Pagination allows you to break up a collection of data (gallery, news items, etc...) into different pages. It can work in conjuction with a database, flat file, or any other collection.

I have written code over and over again to paginate data on various websites before I finally decided I needed a better way to do this. This class will allow you to easily implement pagination and help make your code cleaner and easier to read.

Who is PaginateIt for?

PaginateIt is for anyone that wants to implement pagination on their own site, a friend's site, or even a client's site.

Examples of Usage

View Examples of PaginateIt Usage.

Methods Documented

GetCurrentPage()
Returns the number of the page that is displayed. Usage is optional.
GetPageCount()
Returns the total number of pages required to represent the entire collection. Usage is optional.
GetPageLinks( string format )
Accepts a string that specifies the format of the output that is returned.
{c}
Replaced with the current page number.
{links:#:separator}
This is where the actual page numbers will be shown. The "#" variable is a number that specifies how many page links will be shown. The "separator" variable specifies the string that will separate each page link.
{p:anchortext}
Depending upon the pagination mode, this will be replaced with a link to the previous page. The text specified by "anchortext" will be used as the anchor text.
{n:string}
Depending upon the pagination mode, this will be replaced with a link to the next page. The text specified by "anchortext" will be used as the anchor text.
{t}
Replaced by a number representing the total number of pages in the collection.

Example: <?php echo $PaginateIt->GetPageLinks('Page {c} of {t}: {p:< Back} {links:5: • } {n:Next >}'); ?>
Output: Page 1 of 20: < Back 12345 Next >

Note: You can insert HTML tags in the format string parameter so that you can create classes to style the ouput using CSS.

GetQueryString()
Returns the querystring without the page variable. Useful for passing parameters other than the page number between pages. Usage is optional.
GetSqlLimit()
Returns a string with the LIMIT portion of a MySQL SELECT statement. Usage is optional.

Example: <php $query = mysql_query("SELECT * FROM table" . $PaginateIt->GetSqlLimit()); >

SetCurrentPage( integer value )
Assigns the current page number to the currentPage property of the PaginateIt object. Usage is optional.
SetItemCount( integer value )
Assigns the number of items in the collection being paginated to the itemCount property of the PaginateIt object.
SetItemsPerPage( integer value )
Assigns the number of items to be displayed on a page to the itemsPerPage property of the PaginateIt object so that the total number of pages can be calculated.
SetLinksHref( string string )
Assigns the parameter to the linksHref property of the PaginateIt object. This property is used as the value of the href attribute on all links output to the page from the PaginateIt object. This method is called in the constructor method to point all links back to the page that is calling it. Usage is optional.
SetPaginationMode( string string )
Accepts three possible values to change the pagination behavior. (Jump, Slide, Skip) Defaults to Slide mode. View Examples of PaginateIt Usage to see the differences between the pagination modes.
SetQueryStringVar( string string )
Assigns the parameter to the queryStringVar property of the PaginateIt object. This property determines the variable that indicates which page is being viewed in the querystring. The constructor method sets the default value as page. Usage is optional.
SetQueryString( string string )
Assigns the parameter to the queryString property of the PaginateIt object. This property will be passed between pages as the query string. The constructor method calls this method to automatically pass query string variables between pages, so this method should only be used in special circumstances.

This script uses The MIT License which basically says you can use this script for anything you want, commercial or otherwise, as long as the copyright and license remains intact.

Copyright © 2006 Brady Vercher

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.