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

<html>
<head>
<title>Example 4</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 4</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
		$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. The previous and next links are pretty much set up like in
	//the last example.  What is new here is the numbered links.
	//===========================================================================
	        if($a->getPrevious())
		        {
		        echo "<a href=\"" . $a->getPageName() . "?page=" . $a->getPrevious() . "\">Previous</a> ";
		        }
					
				 //===========================================================================
				 //start making the numbered links. The method getLinkArr() returns an array of
				 //all the numbered links that should appear on the page. The method getCurrent()
				 //returns the current page. I put the values returned in a variable to avoid calling
				 //the method each time there is a loop.
						$links = $a->getLinkArr();
						$current=$a->getCurrent();
		      foreach($links as $link)
	          {
						//if the current page is the same as $link then this number will show in text
						//as the current page. If $link is not the same as the current page then it will 
						//appear as a numbered link.
	          if($link == $current)
					    {
					     echo " $link ";
							//The method getPageName() gets the name of the page to use in the url.
					    } else { echo "<a href=\"" . $a->getPageName() . "?page=$link\">" . $link . "</a> ";
					    }
		          } 
						if($a->getNext())
		          {
		          echo "<a href=\"" . $a->getPageName() . "?page=" . $a->getNext() . "\">Next</a> ";
		          }
	       
					//==============================================================================
					//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 shows how to make a page with numbered
links.</p>
<a href="index.php">Back to Index</a>
</body>
</html>
Return current item: Paginator