Hi all, i have this program for limiting the list of records in a single page,,,,,,,but how to incorporate this in my program.......i am unable to understand it..........what is test.php.......can any one explain me pls........in my program i am just displaying n number of items......i got this program, from some one.....but dont know how to proceed.
<?php
session_start();
include("pagenavigation.php");
include("header.php") ;
$totalResults = 20;
$resultsPerPage = 5;
$page = $_GET[page];
$startHTML = "<b>Showing Page {page} of {pages}</b>: Go to Page ";
$appendSearch = "&a=1&b=2";
$range = 5;
$link_on = "<a href='test.php?page={num}{appendSearch}'><b>{num}</b></a>";
$link_off = "<a href='test.php?page={num}{appendSearch}'>{num}</a>";
$back = " <a href='test.php?page=1{appendSearch}'><<</a> ";
$forward = " <a href='test.php?page={pages}{appendSearch}'>>></a> ";
$myNavigation = New PageNavigation($totalResults, $resultsPerPage, $page, $startHTML, $appendSearch, $range, $link_on, $link_off, $back, $forward);
echo $myNavigation->getHTML();
?>
<?php
class PageNavigation {
/* Global Variables */
var $totalResults;
var $resultsPerPage;
var $page;
var $pages;
var $startHTML;
var $appendSearch;
var $range;
var $link_on;
var $link_off;
var $back;
var $forward;
var $product;
/****************************************
* Constructor *
*****************************************/
function PageNavigation($totalResults, $resultsPerPage, $page, $startHTML, $appendSearch, $range, $link_on, $link_off, $back, $forward) {
$this->totalResults = $totalResults;
$this->resultsPerPage = $totalResults;
$this->page = $page;
$this->pages = ceil($totalResults / $resultsPerPage);
$this->product = $startHTML;
$this->appendSearch = $appendSearch;
$this->range = $range;
$this->link_on = $link_on;
$this->link_off = $link_off;
$this->back = $back;
$this->forward = $forward;
}
/****************************************
* Replace Alias *
*****************************************/
function replace_alias() {
$this->product = str_replace("{page}", $this->page, $this->product);
$this->product = str_replace("{pages}", $this->pages, $this->product);
$this->product = str_replace("{appendSearch}", $this->appendSearch, $this->product);
}
/****************************************
* GET HTML *
*****************************************/
function getHTML()
{
$pageLinks = array();
//loop array of needed pages
for ($i=0;$i<$this->pages;$i++)
{
$num = $i+1;
$showNum = false;
if ($this->page >= $num && $this->page - $this->range <= $num)
$showNum = true;
if ($this->page <= $num && $this->page + $this->range >= $num)
$showNum = true;
if ($showNum == true)
{
if (($num) == $this->page)
{
array_push($pageLinks, str_replace("{num}", $num, $this->link_on));
}
else
{
array_push($pageLinks, str_replace("{num}", $num, $this->link_off));
}
}
}
if (($this->page - $this->range) > 1)
$this->product .= $this->back;
if (($this->page + $this->range) < $this->pages)
$this->product .= $this->forward;
$this->replace_alias();
}
}