PHP Classes

File: Paginator_example.php

Recommend this page to a friend!
  Classes of Ellery Leung  >  SimplePaginator  >  Paginator_example.php  >  Download  
File: Paginator_example.php
Role: Example script
Content type: text/plain
Description: Paginator example
Class: SimplePaginator
Retrieve MySQL query result rows to show in pages
Author: By
Last change:
Date: 14 years ago
Size: 1,252 bytes
 

Contents

Class file image Download
<?php
include("Paginator.class.php");

//Connect to MYSQL server
mysql_connect("localhost", "root", "");
mysql_select_db("mysql");

//Start getting records
/*
    To use this class, you need to set 2 things:
    1) The SQL you want to do pagination
    2) Items per page
   
    Notes:
    - The getTotalPages() function is worked only after you set the SQL.
    - Pages start at 1.
    - The parameter passed to a funciton should be a non-zero, positive number.
   
*/
$p = new Paginator();
$p->setSQL("SELECT User FROM user"); //<<< Must set
$p->setItemsPerPage(3); //<<< Must set

print 'The total number of pages is: '.$p->getTotalPages(); print '<br/><br/>';

$result_resources = $p->getPageNumber(1); //<<< Print page 1
printRows($result_resources);

$result_resources = $p->getPageNumber(2); //<<< Print page 2
printRows($result_resources);

$result_resources = $p->getPageNumber(3); //<<< Print page 3
printRows($result_resources);

$result_resources = $p->getPageNumber(4); //<<< Print page 4
printRows($result_resources);

$result_resources = $p->getPageNumber(5); //<<< Print page 5
printRows($result_resources);

function
printRows($res){
    while(
$row = mysql_fetch_object($res)){
        print
$row->User.'<br/>';
    }
}

?>

For more information send a message to info at phpclasses dot org.