PHP Classes

File: paginator_doc.php

Recommend this page to a friend!
  Classes of ted kappes   Paginator   paginator_doc.php   Download  
File: paginator_doc.php
Role: Documentation
Content type: text/plain
Description: General documentation
Class: Paginator
Spliting database query result sets between pages.
Author: By
Last change:
Date: 20 years ago
Size: 4,963 bytes
 

Contents

Class file image Download
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html> <head> <title>Using Paginator</title> <style type="text/css"> <!-- body { margin-top: 20px; margin-left: 50px; margin-right: 50px; background-color: #FFFF99; font-family: Verdana; } h1 { font-size: 150%; } h2 { font-size: 125%; } --> </style> </head> <body> <h1>Using Paginator</h1> <h2>Using Paginator without Paginator_html</h2> <p>Used alone Paginator reguires that you use the values that the Paginator methods return to create your links. This will give you the most flexibility.Regardless of the data source that you use, you will follow these steps each time you use Paginator.</p> <p>include the Paginator class<br/> <strong>include(</strong>"include/paginator.php"<strong>);</strong></p> <p>Make a new Paginator object<br/> <strong>$a =& new Paginator(</strong>$_GET['page'],$num_rows<strong>);</strong><br /> In this instance it gets the current page by the get method. $num_rows will be the total items in your data source. For example it could be the number of rows in your database.</p> <p><strong>$a->set_Limit(</strong>4<strong>);</strong><br /> This will be your offset. For example if your base is 0, pages 1 though 4 will be retrieved. It left empty 5 is the default.</p> <p><strong>$a->set_Links(</strong>3<strong>);</strong><br /> If you are using numbered links then this will set the number of links to appear before and after the current page. For example if you have 10 pages and 5 is the current page and 3 is used in <strong>set_Links()</strong>, then the result will be <u>2</u> <u>3</u> <u>4</u> <strong>5</strong> <u>6</u> <u>7</u> <u>8</u>. The default for <strong>set_Links()</strong> is five. You do not need to use <strong>set_Links()</strong> if you are not using numbered links. </p> <p><strong>$limit1 = $a->getRange1();</strong><br /> This will return the base that you can use in your query for example.<br /> One way you can use this is with mySQL LIMIT.</p> <p><strong>$limit2 = $a->getRange2();</strong><br /> This will return the offset that you can use in your query for example.<br /> One way you can use this is with mySQL LIMIT.</p> <h1>Using Paginator with Paginator_html</h1> <p>Paginator_html at the moment has 2 sets of links that you can use without having to set these up yourself. I plan to add a few more if anyone finds this helpful. Most of the steps are the same except for what is below</p> <p>include the Paginator_html class in addition to the Paginator class<br/> <strong>include(</strong>"include/paginator.php"<strong>);</strong><br /> <strong>include(</strong>"include/paginator_html.php"<strong>);</strong> </p> <p><strong>$a =& new Paginator_html(</strong>$_GET['page'],$num_rows<strong>);</strong><br /> Make a new new Paginator_html object instead of a Paginator object.</p> <p>Instead of using the Paginator methods you can use the following to methods to make your links<br /></a> <strong>$a->firstLast();</strong><br /> Will make a set of links like this: 5 of 8 of 25 <u>First</u> | <u>Prev</u> | <u>Next</u> | <u>Last</u> |<br /> <strong>$a->previousNext();</strong><br /> Will make a set of links like this: <u>Previous</u> <u>1</u> <u>2</u> <u>3</u> 4 <u>5</u> <u>6</u> <u>7</u> <u>Next</u> </p> <a name="pmethods"> <h2>Paginator Methods</h2> <p>What follows is a list of Paginator methods and what they return. Using these methods will give you the greatest flexibility in making your links</p> <p><strong>getTotalItems()</strong><br /> This will return the total items in your data source.</p> <p><strong>getRange1()</strong><br /> Method to get the base number to use in queries and such. </p> <p><strong>getRange2()</strong><br /> Gets the offset.</p> <p><strong>getFirstOf()</strong><br /> Method to get the first of number as in 5 of .</p> <p><strong>getSecondOf()</strong><br /> Method to get the second number in a series as in 5 of 8.</p> <p><strong>getTotalPages()</strong><br /> method to get the total number of pages.</p> <p><strong>getTotalItems()</strong><br /> Method to get the total items in series</p> <p><strong>getFirst()</strong><br /> method to get the first link number.</p> <p><strong>getLast()</strong><br /> method to get the last link number.</p> <p><strong>getPrevious()</strong><br /> Method to get the number of the link previous to the current link.</p> <p><strong>function getCurrent()</strong><br /> Method to get the current page name.</p> <p><strong>getNext()</strong><br /> Method to get the number of the link after the current link.</p> <p><strong>getPageName()</strong><br /> Method to get the current page name. Is mostly used in links to the next page.</p> <p><strong>getLinkArr()</strong><br /> Method that returns an array of the numbered links that should be displayed.</p> </body> </html>