Location: PHPKode > scripts > Paginator > paginator/example3.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Example 3</title>
<style type="text/css">
<!-- 
body { margin-top: 20px;
			 margin-left: 150px;
			 margin-right: 150px;
			 background-color: #FFFF99; 
			 font-family: Verdana;
 } 
h1 { font-size: 150%;
 }
-->
</style>
</head>
<center>
<body>
<h1>Example 3</h1>
<?php
  //=================================================================================
	//This shows how to set things up to get your input from an array.  This could be
	//used to make an image gallery or to display anything else you might store in
	//an array. This is an example of how you can use Paginator alone to have the most 
	//flexibility in setting up your links.
	//==================================================================================
  //include the main class
	include("include/paginator.php");
	//Makes the array used in this example.
		for($i=0; $i < 25; $i++)
			{
			$p=$i+1;
			$pictures[$i]="pict" . $p . ".jpg";
			}
		//gets the total number of items
    $num_rows = count($pictures);
		//========================================================================
		//Parts used to make a new paginator 
		//========================================================================
		//Makes new Paginator.  Current page here is sent by the get method. 
		//$num_rows is the total items in the source.
    $a =& new Paginator($_GET['page'],$num_rows);
    //sets the number of records displayed
		//defaults to five
		$a->set_Limit(4); 
		//if using numbered links this will set the number before and behind 
		//the current page. defaults to five.
		//not used in this example.
		//$a->set_Links(3);  
		//gets starting point.
		$limit1 = $a->getRange1();  
		//gets number of items displayed on page.
		$limit2 = $a->getRange2();  
		//=========================================================================
		//Printing out the items in the array
		for($j=$limit1; $j < $limit1 + $limit2; $j++)
			{
			echo "<strong>" . $pictures[$j] . "</strong></p>";
			}
	//===========================================================================
	//This shows how to create your links using the output availiable from the
	//Paginator class.  It is a good example to study since it shows most of
	//the information that Paginator can output.
	//===========================================================================
	         //check to see if current page is one. If so there will be no link.
	         if($a->getCurrent()==1)
		         {
		         $first = "First | ";
		         } else { $first="<a href=\"" .  $a->getPageName() . "?page=" . $a->getFirst() . "\">First</a> |"; }  
					 //check to see that getPrevious() is returning a value. If not there will be no link.
		       if($a->getPrevious())
		         {
		         $prev = "<a href=\"" .  $a->getPageName() . "?page=" . $a->getPrevious() . "\">Prev</a> | ";
		         } else { $prev="Prev | "; }
		       //check to see that getNext() is returning a value. If not there will be no link.
	         if($a->getNext())
		         {
		         $next = "<a href=\"" . $a->getPageName() . "?page=" . $a->getNext() . "\">Next</a> | ";
		         } else { $next="Next | "; }
		
		       //check to see that getLast() is returning a value. If not there will be no link.
		       if($a->getLast())
		         {
		         $last = "<a href=\"" . $a->getPageName() . "?page=" . $a->getLast() . "\">Last</a> | ";
		         } else { $last="Last | "; }
						 //since these will always exist just print out the values.  Result will be
						 //something like 1 of 4 of 25
		          echo $a->getFirstOf() . " of " .$a->getSecondOf() . " of " . $a->getTotalItems() . " ";
							//print the values determined by the if statements above.
		          echo $first . " " . $prev . " " . $next . " " . $last;
					//==============================================================================
					//end of example
	
	?>
</center>
<p>This example uses the Paginator class. I use an array here to show that you 
can use this class with sources other then a database. Also I did this so you could
get an idea of how this works without having to go to the trouble of setting up a
database. 
<p>
When you use Paginator alone you will need to use the items returned from methods to
make your own links.  This gives you the most flexibility. Look at the source code for
this page to see how to do this.  This source is a good example because it uses most
of the methods of the class.</p>
<a href="index.php">Back to Index</a>
</body>
</html>
Return current item: Paginator