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();

}

}

Hi,

I have done the pagination check it.

<?phpsession_start();
include('database.php');
//Information for paging
//**************************************************************************	$page_name="yourPage.php"; 
	$limit=sql_quote($_GET['limit']); // Read the limit value from query string.
	$start=sql_quote($_GET['start']);								// To take care global variable if OFF
	if(!($start > 0))
	{                         // This variable is set to zero for the first page
		$start = 0;
	}
	
	$eu = ($start - 0); 
	if(!$limit > 0 )
	{ // if limit value is not available then let us use a default value
		$limit = 10;    // No of records to be shown per page by default.
	}                             
	$this1 = $eu + $limit; 
	$back = $eu - $limit; 
	$next = $eu + $limit; 
	//*****************************************************************

$result = mysql_query("SELECT * FROM  autoalto_mail" ); 

//code for paging
//**************************************************************************	$selcount = "SELECT * FROM  autoalto_mail" ;
	$result2=mysql_query($selcount);
	$nume=mysql_num_rows($result2);
//**************************************************************************
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>
<?
}

/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
	       	if($nume > $limit)
	       	{
	       		//Counting no of pages and the current page.
	       		$totnumofpages = round($nume/$limit);
	       		$i=0;
	       		$l=1;
	       		for($i=0;$i < $nume;$i=$i+$limit)
				{
					if($i == $eu)
					{
						$currentpage= $l;
					}
					$l=$l+1;
				}	
				       		
				echo "<div height=28 align=right><table cellpadding=3 cellspacing=1 border=0 height=28><tr><td>Page ".$currentpage." / ".$totnumofpages."</td>";
				//// if our variable $back is equal to 0 or more then only we will display the link to move back //////// 
				if($back >=0) 
				{ 
					print "<td  align='left'><a href='$page_name?start=$back&limit=$limit'>&lt;</a></td>"; 
				} 
				//////////////// We will not display the current page as a link ///////////
				$i=0;
				$l=1;
				for($i=0;$i < $nume;$i=$i+$limit)
				{
					if($i <> $eu)
					{
						echo "<td align=center><a href='$page_name?start=$i&limit=$limit'><span>$l</span></a></td>";
					}
					else 
					{ 
						echo "<td align=center><span><b>$l</b></span></td>";
					}        /// Current page is not displayed as link 
					$l=$l+1;
				}
				///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
				if($this1 < $nume) 
				{ 
					print "<td align=center width=15><a href='$page_name?start=$next&limit=$limit'><span ><b>&gt;</b></span></a></td>";
				} 
				echo "</tr></table></div>";
			}



mysql_close();

?>

Hi,

Just forgot to tell you one thing.
Change the following line in code with the page name.

$page_name="yourPage.php";

HI i am getting this error:

Fatal error: Call to undefined function sql_quote() in D:\xampp\htdocs\demo\page_new_navigation.php on line 7

Sorry, That is one function that I had used to prevent SQL injection.

Please remove that function from the code.
like

$limit=sql_quote($_GET['limit']);

change it to

$limit=$_GET['limit'];

Hi

Now i am getting this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\xampp\htdocs\demo\page_new_navigation.php on line 43

but it is displaying the table contents thats it.........and its not displaying page navigation link
and its not displaying this
echo $nume;

Hi,

Post the code for page_new_navigation.php page.

becausethe code that I send you should not give problem

Hi here is the code...

<?php
session_start();
include('database.php');
//Information for paging
//**************************************************************************     
    $page_name="yourPage.php";
    //$limit=sql_quote($_GET['limit']); // Read the limit value from query string.
    $limit=$_GET['limit'];
    //$start=sql_quote($_GET['start']);                             // To take care global variable if OFF
    $start=$_GET['start'];
    if(!($start > 0))
    {                         // This variable is set to zero for the first page
        $start = 0;
    }

    $eu = ($start - 0); 
    if(!$limit > 0 )
    { // if limit value is not available then let us use a default value
        $limit = 10;    // No of records to be shown per page by default.
    }                             
    $this1 = $eu + $limit; 
    $back = $eu - $limit; 
    $next = $eu + $limit; 
    //*****************************************************************/





$result = mysql_query("SELECT * FROM  autoalto_mail" ); 

//code for paging
//**************************************************************************    $selcount = "SELECT * FROM  autoalto_mail" ;
    $result2=mysql_query($selcount);
    $nume=mysql_num_rows($result2);
    echo $nume;
//**************************************************************************
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>
<?
}

/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
            if($nume > $limit)
            {
                //Counting no of pages and the current page.
                $totnumofpages = round($nume/$limit);
                $i=0;
                $l=1;
                for($i=0;$i < $nume;$i=$i+$limit)
                {
                    if($i == $eu)
                    {
                        $currentpage= $l;
                    }
                    $l=$l+1;
                }   

                echo "<div height=28 align=right><table cellpadding=3 cellspacing=1 border=0 height=28><tr><td>Page ".$currentpage." / ".$totnumofpages."</td>";
                //// if our variable $back is equal to 0 or more then only we will display the link to move back //////// 
                if($back >=0) 
                { 
                    print "<td  align='left'><a href='$page_name?start=$back&limit=$limit'>&lt;</a></td>"; 
                } 
                //////////////// We will not display the current page as a link ///////////
                $i=0;
                $l=1;
                for($i=0;$i < $nume;$i=$i+$limit)
                {
                    if($i <> $eu)
                    {
                        echo "<td align=center><a href='$page_name?start=$i&limit=$limit'><span>$l</span></a></td>";
                    }
                    else 
                    { 
                        echo "<td align=center><span><b>$l</b></span></td>";
                    }        /// Current page is not displayed as link 
                    $l=$l+1;
                }
                ///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
                if($this1 < $nume) 
                { 
                    print "<td align=center width=15><a href='$page_name?start=$next&limit=$limit'><span ><b>&gt;</b></span></a></td>";
                } 
                echo "</tr></table></div>";
            }



mysql_close();

?>

wat is ur page name

i want to know the page name in which u have stored this page

Hi Use this code, its not giving any error, also change
$page_name="test.php";
with
the name of your page

<?
session_start();
include('database.php');
$page_name="test.php";
//$limit=sql_quote($_GET['limit']); // Read the limit value from query string.
$limit=$_GET['limit'];
//$start=sql_quote($_GET['start']); // To take care global variable if OFF
$start=$_GET['start'];
if(!($start > 0))
{ // This variable is set to zero for the first page
$start = 0;
}

$eu = ($start - 0); 
if(!$limit > 0 )
{ // if limit value is not available then let us use a default value
$limit = 3; // No of records to be shown per page by default.
} 
$this1 = $eu + $limit; 
$back = $eu - $limit; 
$next = $eu + $limit; 
//*****************************************************************/
$result = mysql_query("SELECT * FROM autoalto_mail   limit $eu, $limit" ); 

//code for paging
//************************************************************************** 
$selcount = "SELECT * FROM autoalto_mail" ;
$result2=mysql_query($selcount);
$nume=mysql_num_rows($result2);
echo $nume;
echo "<table>";
//**************************************************************************
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>
<?
}
echo "</table>";
/////////////// Start the buttom links with Prev and next link with page numbers /////////////////
if($nume > $limit)
{
//Counting no of pages and the current page.
$totnumofpages = round($nume/$limit);
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit)
{
if($i == $eu)
{
$currentpage= $l;
}
$l=$l+1;
} 

echo "<div height=28 align=right><table cellpadding=3 cellspacing=1 border=0 height=28><tr><td>Page ".$currentpage." / ".$totnumofpages."</td>";
//// if our variable $back is equal to 0 or more then only we will display the link to move back //////// 
if($back >=0) 
{ 
print "<td align='left'><a href='$page_name?start=$back&limit=$limit'>&lt;</a></td>"; 
} 
//////////////// We will not display the current page as a link ///////////
$i=0;
$l=1;
for($i=0;$i < $nume;$i=$i+$limit)
{
if($i <> $eu)
{
echo "<td align=center><a href='$page_name?start=$i&limit=$limit'><span>$l</span></a></td>";
}
else 
{ 
echo "<td align=center><span><b>$l</b></span></td>";
} /// Current page is not displayed as link 
$l=$l+1;
}
///////////// If we are not in the last page then Next link will be displayed. Here we check that /////
if($this1 < $nume) 
{ 
print "<td align=center width=15><a href='$page_name?start=$next&limit=$limit'><span ><b>&gt;</b></span></a></td>";
} 
echo "</tr></table></div>";
}
mysql_close();
?>

Thank You very much................I got it..........

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.