0

hi all,

the following code is for pagination using php and ajax.

I have 4 records in my table. It queries and echo's that there are 4 records, which is correct, but the pagination is not kicking in. IVe been looking at this for a while and just cant see the error.

When its listing its not showing next and prev

<?
function getConnection(){
	$host = "localhost";
	$usr = "";
	$pwd = "";
	$db = "";
	
	$cid = mysql_connect($host,$usr,$pwd);
	mysql_select_db($db, $cid);
	if (!$cid) { echo("ERROR: " . mysql_error() . "\n");
	}
}

getConnection();

$strPage = $_REQUEST[Page];
if($_REQUEST[mode]=="Listing"){
$query = "SELECT * FROM tbl_example";
$result = mysql_query($query) or die(mysql_error());
 
echo "rows" . $Num_Rows = mysql_num_rows ($result);
 
########### pagins
$Per_Page = 2;   // Records Per Page
 
$Page = $strPage;
if(!$strPage)
{
	$Page=1;
}
 
$Prev_Page = $Page-1;
$Next_Page = $Page+1;
 
$Page_Start = (($Per_Page*$Page)-$Per_Page);
if($Num_Rows=$Per_Page)
{
	$Num_Pages =1;
}
else if(($Num_Rows % $Per_Page)==0)
{
	$Num_Pages =($Num_Rows/$Per_Page) ;
}
else
{
	$Num_Pages =($Num_Rows/$Per_Page)+1;
	$Num_Pages = (int)$Num_Pages;
}
}
$query.=" order  by id ASC LIMIT $Page_Start , $Per_Page";
$result = mysql_query($query) or die(mysql_error());
?>
<table border="0">

<tr>
<td>Name</td>
<td>Email</td>
</tr>
<?php
// Insert a new row in the table for each person returned
while($data= mysql_fetch_array($result)){ ?>
<tr>
<td><?php echo $data['name']; ?></td>
<td><?php echo $data['email']; ?></td>
</tr>
<div class="resultbg pagination">
<?php 
echo "previous page " . $Prev_Page;
echo "number of pages " . $Num_Pages;
if($Prev_Page) {
	echo " <li><a href=\"JavaScript:SANAjax('Listing','$Prev_Page')\"> << Back</a> </li>";
	}
 
for($i=1; $i<=$Num_Pages; $i++){
	if($i != $Page){
		echo " <li><a href=\"JavaScript:SANAjax('Listing','$i')\">$i</a> </li>";
		}else{
		echo "<li class='currentpage'><b> $i </b></li>";
		}
		}
if($Page!=$Num_Pages)
{
	echo " <li><a href=\"JavaScript:SANAjax('Listing','$Next_Page')\">Next >></a> </li>";
}
?>
</div>
<?php
}

?>
</table>
2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by sourcebits
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.