| 
<?php
/*
 *******************************************************
 simple_page_iterator.php
 
 A simple example of using the PHP class PageIterator
 *******************************************************
 */
 // Include the PageIterator file
 $includeFolder = './';
 require_once $includeFolder . 'PageIterator.inc';
 echo '<?xml version="1.0" encoding="UTF-8"?>' . "\r\n";
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
 
 <head>
 <title>Simple PageIterator Example</title>
 <meta name="AUTHOR" content="Karsten Juul Mikkelsen" />
 <meta name="description" content="A simple example of using the PHP class PageIterator" />
 </head>
 
 <body>
 
 <h1>Simple PageIterator example</h1>
 <?php
 // Create an array of circle dimensions to use as data
 $circles = array();
 for ($i = 0; $i < 100; $i++) {
 $circles[$i]['radius'] = ($i + 1) * 2;
 $circles[$i]['diameter'] = $circles[$i]['radius'] * 2;
 $circles[$i]['perimeter'] = number_format($circles[$i]['diameter'] * pi(), 2);
 $circles[$i]['area'] = number_format(($circles[$i]['radius'] * $circles[$i]['radius']) * pi(), 2);
 }
 
 // $pageNo is global variable sent as an argument in the URL
 if (empty($pageNo)) $pageNo = 1;
 
 // Create a PageIterator object for the specified page number
 $paginator = new PageIterator(sizeof($circles), $pageNo);
 
 // Print links to the previous and next pages
 echo "<div align=\"center\"> \r\n";
 while ($paginator -> hasNextPage()) {
 $ndx = $paginator -> nextPage();
 if ($ndx == $pageNo) { // The current page should not be a link
 echo "[Page $ndx]";
 echo '  ';
 }
 else {
 echo '<a href="' . basename($PHP_SELF) . "?pageNo=$ndx" . '">';
 echo "[Page $ndx]";
 echo '</a>  ';
 }
 }
 echo " \r\n </div> \r\n";
 echo "<br /><br /> \r\n";
 
 // Print a table of the circle dimensions
 echo "<table align=\"center\" cellspacing=\"5\"> \r\n";
 echo "    <caption>Circle Dimensions</caption> \r\n";
 echo "    <tr> \r\n";
 echo "        <th>#</th> \r\n";
 echo "        <th>Radius</th> \r\n";
 echo "        <th>Diameter</th> \r\n";
 echo "        <th>Perimeter</th> \r\n";
 echo "        <th>Area</th> \r\n";
 echo "    </tr> \r\n";
 // Output elements from $circles
 while ($paginator -> hasNextElement()) {
 $ndx = $paginator -> nextElement();
 echo "    <tr align=\"right\"> \r\n";
 echo "        <td>" . ($ndx + 1) . ".</td> \r\n";
 echo "        <td>" . $circles[$ndx]['radius'] . "</td> \r\n";
 echo "        <td>" . $circles[$ndx]['diameter'] . "</td> \r\n";
 echo "        <td>" . $circles[$ndx]['perimeter'] . "</td> \r\n";
 echo "        <td>" . $circles[$ndx]['area'] . "</td> \r\n";
 echo "    </tr> \r\n";
 }
 echo "</table> \r\n";
 
 ?>
 </body>
 </html>
 
 |