Hi here is my code......i want page navigation for this code......i have the page navigation code but i dont know how to incorporate it please help me........
<?php
session_start();
include('database.php');
$result = mysql_query("SELECT * FROM autoalto_mail" );
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td width="5%"></td>
<td><? echo $row['From_user'];?>
<td><a href="contractor_mail_action_contents.php?mail_id=<? echo $row['mail_id'];?>">
<?echo $row['subject'];
$subj=$row['subject'];
session_register("subj");?> </a></td>
<td><?echo $row['date']?></td>
</tr>
<tr>
<td width="5%"></td>
<td colspan="4" style="background-repeat: repeat-x;" background="images/dot.jpg" height="0" width="300"></td>
</tr>
<?
}
mysql_close();
?>
page navigation code:
<?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();
}
}