Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Romil Jayme  >  My Pagination  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example usage of the pagination class
Class: My Pagination
Display links for browsing database query results
Author: By
Last change:
Date: 2011-10-01 05:48
Size: 3,746 bytes
 

Contents

Class file image Download

<?Php
include("class.mypagination.php");

$host "localhost";
$user "root";
$pass "";
$dbname "test_users";
$tbname "users";

/*
* The table on this example has only 2 fields
* id_user, user_name
*/

// database here
$db mysql_connect($host$user$pass) or die("Failed to connect to mysql");
mysql_select_db($dbname) or die("Failed to connect to database");


$offset 3// number of rows per page

$sql "SELECT * FROM $tbname";
$query mysql_query($sql);
$total_results mysql_num_rows($query);

// ==========================================================================================================


echo 'Offset (Number of rows in a page): '.$offset;
echo 
'<br /><br />';
echo 
'---- 1. basic next/prev  ---------------------------------------------';
echo 
'<br /><br />';
echo 
'RESULTS';
echo 
'<br />';

// IMPLEMENTATION
$pg = new MyPagination();
//$pg->setgetvar('pgs'); // use this when you are using a different page GET variable like "index.php?pgs=1"
$result $pg->page_nextprev($offset$total_results$_GET['page']);

$sql1 "SELECT * FROM $tbname ".$result['limit'];
$query1 mysql_query($sql1);
$page_results mysql_num_rows($query1);

while (
$row mysql_fetch_array($query1)) {
        echo 
$row['id_user'].' => '.$row['user_name'];
        echo 
'<br />';
}

echo 
'<br /><br />';
//echo $result['limit'];
echo '<br />';
//echo $temp['prev'];
//echo '<br />';
//echo $temp['next'];
//echo '<br />';
echo $result['default'];
echo 
'<br />';
echo 
'Showing '.$result['begin_rec'].' - '.$result['end_rec'].' out of '.$result['total_rec'];

// ==========================================================================================================

echo '<br /><br />';
echo 
'---- 2. Page Numbers  ---------------------------------------------';
echo 
'<br /><br />';
echo 
'RESULTS';
echo 
'<br />';


// IMPLEMENTATION
$pg2 = new MyPagination();
//$pg->setgetvar('pgs'); // use this when you are using a different page GET variable like "index.php?pgs=1"
$result2 $pg2->page_series($offset$total_results$_GET['page']);

$sql2 "SELECT * FROM $tbname ".$result['limit'];
$query2 mysql_query($sql2);
$page_results mysql_num_rows($query2);

while (
$row mysql_fetch_array($query2)) {
        echo 
$row['id_user'].' => '.$row['user_name'];
        echo 
'<br />';
}

echo 
'<br /><br />';
//echo $result2['limit'];
echo '<br />';
//echo $temp['prev'];
//echo '<br />';
//echo $temp['next'];
//echo '<br />';
echo $result2['default'];
echo 
'<br />';
echo 
'Showing '.$result2['begin_rec'].' - '.$result2['end_rec'].' out of '.$result2['total_rec'];

// ==========================================================================================================

echo '<br /><br />';
echo 
'---- 3. Select Field (Drop Down)  ---------------------------------------------';
echo 
'<br /><br />';
echo 
'RESULTS';
echo 
'<br />';


// IMPLEMENTATION
$pg3 = new MyPagination();
//$pg->setgetvar('pgs'); // use this when you are using a different page GET variable like "index.php?pgs=1"
$result3 $pg3->page_selectField($offset$total_results$_GET['page']);

$sql3 "SELECT * FROM $tbname ".$result['limit'];
$query3 mysql_query($sql3);
$page_results mysql_num_rows($query3);

while (
$row mysql_fetch_array($query3)) {
        echo 
$row['id_user'].' => '.$row['user_name'];
        echo 
'<br />';
}

echo 
'<br /><br />';
//echo $result3['limit'];
echo '<br />';
//echo $temp['prev'];
//echo '<br />';
//echo $temp['next'];
//echo '<br />';
echo $result3['default'];
echo 
'<br />';
echo 
'Showing '.$result3['begin_rec'].' - '.$result3['end_rec'].' out of '.$result3['total_rec'];


mysql_close($db);

?>