PHP Classes

File: auto_paging_test

Recommend this page to a friend!
  Classes of rafi randoni   Auto-Paging   auto_paging_test   Download  
File: auto_paging_test
Role: Example script
Content type: text/plain
Description: sample usage of class Auto-Paging
Class: Auto-Paging
Paginate MySQL database table record listings
Author: By
Last change: update example file
Date: 9 years ago
Size: 1,817 bytes
 

Contents

Class file image Download
<?php
/*
    Sample usage of Auto-Paging class
    I'm sorry for my bad english...
    hope the Auto-Paging class will be usefull for you...
    if you have comments or feedback, you can send me an email... ^_^
*/

/*
Database :
    create table class_examples;
    use class_examples;
    create table test(
        id int primary key AUTO_INCREMENT,
        name varchar(255),
        address text
    );
    insert into test(name, address) values
        ('a', 'address 1'),
        ('b', 'address 2'),
        ('c', 'address 3'),
        ('d', 'address 4'),
        ('e', 'address 5'),
        ('f', 'address 6');
*/

/*
    Including the class file
*/
include "AutoPaging.php";

/*
    Initialize $page, its usefull for detect current page
*/
$page = 1;

/*
    Check if $_GET['page'] is exist or not,
    if it exists, so it will used as reference
    for the current page
*/
if(isset($_GET['page']))
{
   
$page = $_GET['page'];
}

/*
    Options :
        - db_host : Database Host, Example: "localhost"
        - db_user : Database user, default mysql user is "root"
        - db_pass : Database password
        - db_name : Database name
        - table_name : Database table name
        - limit : Data per page
        - current_page : Current Page
*/
$options = array(
   
'db_host' => 'localhost',
   
'db_user' => 'root',
   
'db_pass' => '',
   
'db_name' => 'class_examples',
   
'table_name' => 'test',
   
'limit' => 2,
);

$paging = new AutoPaging($options, $page);

/*
    To get the content, just simply use getContent() function
    here's the example...
    its just simple example...
    you can modify or even create a new one better from this one....
*/
foreach($paging->getContent() as $row)
{
    echo
$row['name'];
    echo
" : ";
    echo
$row['address'];
    echo
"<br />";
}

/*
    the last but not least, here's how to get the pagination...
*/
echo $paging->getPaging();
?>