PHP Classes

File: example2.php

Recommend this page to a friend!
  Classes of ted kappes  >  Paginator  >  example2.php  >  Download  
File: example2.php
Role: Example script
Content type: text/plain
Description: Working example of use
Class: Paginator
Spliting database query result sets between pages.
Author: By
Last change:
Date: 12 years ago
Size: 3,248 bytes


Class file image Download
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<title>Example 2</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%;
<h1>Example 2</h1>
    //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 page uses Paginator_html for the pre-made links. The results
    //are pretty basic. You should be able to use something like CSS to customize these
    //for you own site. This page uses the previousNext() method.
  //include the main class
//include the extension that makes the pre-made links
//Makes the array used in this example.
for($i=0; $i < 25; $i++)
$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_html. Current page here is sent by the get method.
        //$num_rows is the total items in the source.
$a =& new Paginator_html($_GET['page'],$num_rows);
//sets the number of records displayed
        //defaults to five
// if using numbered links this will set the number before and behind
        //the current page.
        //defaults to five
//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++)
"<strong>" . $pictures[$j] . "</strong></p>";
        //Put this where you want your links to appear
            //uncomment for some info that may be helpful in debugging.
            //echo '<pre>'; print_r($a); echo '</pre>';
<p>This is an example of one of the pre-made set of links. It uses the Paginator
class and the Paginator_html extension 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. This output is fairly plain which should make it easier to use something like
CSS to fit it into the look of your own site.
Check the source code of this page to see how to set something like this up.</p>
<a href="index.php">Back to Index</a>