0

pagination works well, it even displays the rows i wanted, however, my problem now is that i cannot access or it does not display the next rows from my database, i think there is some problem with regards to my next/previous/last/first links,,

please help me asap, tnx!

$result = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus") or die(mysql_error()); 
			echo "<center>";
			//This checks to see if there is a page number. If not, it will set it to page 1 
			if (!(isset($pagenum))) 
			{ 
				$pagenum = 1; 	
			} 

			$rows = mysql_num_rows($result);				//Here we count the number of results 
			$page_rows = 4; 						//This is the number of results displayed per page 
			$last = ceil($rows/$page_rows); 				//This tells us the page number of our last page 

			if ($pagenum < 1) 						//this makes sure the page number isn't below one, or more than our maximum pages 
			{ 
				$pagenum = 1; 		
			} 
			elseif ($pagenum > $last) 
			{ 
				$pagenum = $last; 
			} 
				
			$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;	//This sets the range to display in our query 			
			$result2 = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus $max") or die(mysql_error()); 

			$resultCount = mysql_query("SELECT COUNT(*) FROM sec_ph") or die(mysql_error());  
			$count = mysql_result($resultCount,0,0);
			echo "<b></center>Record Count: </b> $count record(s)<br><br><center>";

			echo "<table border = 1 bordercolor='#996633' cellpadding = 4><tr  bgcolor = #FFFFCC><th><font size = 2>Type</th><th><font size = 2>Customer</th></tr>";

			while($row = mysql_fetch_array($result2))
			{
				echo "<tr><td><font size = 2>"; 		
				echo $row['phType'];		
         				echo "</td><td><font size = 2>"; 		
				echo $row['phCustomer'];		
         				echo "</td></tr>"; 
			}
			echo "</table>";

			echo "<br><br><center>Page $pagenum of $last<br><br>";			// This shows the user what page they are on, and the total number of pages

			// First we check if we are on page one. 
			//If we are then we don't need a link to the previous page or the first page so we do nothing. 
			//If we aren't then we generate links to the first page, and to the previous page.
			if ($pagenum == 1) 
			{
			} 
			else 
			{
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
				echo " ";
				$previous = $pagenum-1;
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>Previous</a> ";
			} 		

			//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
			if ($pagenum == $last) 
			{
			} 
			else 
			{
				$next = $pagenum+1;
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next</a> ";
				echo " ";
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
			}
3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by futhonguy
0

<!------------- Try this, its your code only and also working fine --->

<?php

$con = mysql_connect("localhost", "root","");
mysql_select_db("test",$con);

$result = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus") or die(mysql_error());

$pagenum = $_GET["pagenum"];
echo "<center>";
//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

$rows = mysql_num_rows($result); //Here we count the number of results
$page_rows = 4; //This is the number of results displayed per page
$last = ceil($rows/$page_rows); //This tells us the page number of our last page

if ($pagenum < 1) //this makes sure the page number isn't below one, or more than our maximum pages
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}

$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This sets the range to display in our query
$result2 = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus $max") or die(mysql_error());

$resultCount = mysql_query("SELECT COUNT(*) FROM sec_ph") or die(mysql_error());
$count = mysql_result($resultCount,0,0);
echo "<b></center>Record Count: </b> $count record(s)<br><br><center>";

echo "<table border = 1 bordercolor='#996633' cellpadding = 4><tr bgcolor = #FFFFCC><th><font size = 2>Type</th><th><font size = 2>Customer</th></tr>";

while($row = mysql_fetch_array($result2))
{
echo "<tr><td><font size = 2>";
echo $row;
echo "</td><td><font size = 2>";
echo $row;
echo "</td></tr>";
}
echo "</table>";

echo "<br><br><center>Page $pagenum of $last<br><br>"; // This shows the user what page they are on, and the total number of pages

// First we check if we are on page one.
//If we are then we don't need a link to the previous page or the first page so we do nothing.
//If we aren't then we generate links to the first page, and to the previous page.
if($pagenum>1)
{

echo " <a href='{$_SERVER}?pagenum=1'>First</a> ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER}?pagenum=$previous'>Previous</a> ";
}

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else
{
$next = $pagenum+1;
echo " <a href='{$_SERVER}?pagenum=$next'>Next</a> ";
echo " ";
echo " <a href='{$_SERVER}?pagenum=$last'>Last</a> ";
}
?>
<!------------------------ End of replay ----------------------->

pagination works well, it even displays the rows i wanted, however, my problem now is that i cannot access or it does not display the next rows from my database, i think there is some problem with regards to my next/previous/last/first links,,

please help me asap, tnx!

$result = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus") or die(mysql_error()); 
			echo "<center>";
			//This checks to see if there is a page number. If not, it will set it to page 1 
			if (!(isset($pagenum))) 
			{ 
				$pagenum = 1; 	
			} 

			$rows = mysql_num_rows($result);				//Here we count the number of results 
			$page_rows = 4; 						//This is the number of results displayed per page 
			$last = ceil($rows/$page_rows); 				//This tells us the page number of our last page 

			if ($pagenum < 1) 						//this makes sure the page number isn't below one, or more than our maximum pages 
			{ 
				$pagenum = 1; 		
			} 
			elseif ($pagenum > $last) 
			{ 
				$pagenum = $last; 
			} 
				
			$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;	//This sets the range to display in our query 			
			$result2 = mysql_query("SELECT * FROM sec_ph ORDER BY phStatus $max") or die(mysql_error()); 

			$resultCount = mysql_query("SELECT COUNT(*) FROM sec_ph") or die(mysql_error());  
			$count = mysql_result($resultCount,0,0);
			echo "<b></center>Record Count: </b> $count record(s)<br><br><center>";

			echo "<table border = 1 bordercolor='#996633' cellpadding = 4><tr  bgcolor = #FFFFCC><th><font size = 2>Type</th><th><font size = 2>Customer</th></tr>";

			while($row = mysql_fetch_array($result2))
			{
				echo "<tr><td><font size = 2>"; 		
				echo $row['phType'];		
         				echo "</td><td><font size = 2>"; 		
				echo $row['phCustomer'];		
         				echo "</td></tr>"; 
			}
			echo "</table>";

			echo "<br><br><center>Page $pagenum of $last<br><br>";			// This shows the user what page they are on, and the total number of pages

			// First we check if we are on page one. 
			//If we are then we don't need a link to the previous page or the first page so we do nothing. 
			//If we aren't then we generate links to the first page, and to the previous page.
			if ($pagenum == 1) 
			{
			} 
			else 
			{
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
				echo " ";
				$previous = $pagenum-1;
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>Previous</a> ";
			} 		

			//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
			if ($pagenum == $last) 
			{
			} 
			else 
			{
				$next = $pagenum+1;
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next</a> ";
				echo " ";
				echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
			}
0

OMG!

Thank you very much, greensoftech...
u r such a blessing!
that's the problem i dont get

thank u so much for the help!

It really means a lot...

0

Hi I tried to use this script to sort out my search result to display in pages. As i am doing a search entry to sort the results into pages, i was only able to view the 1st search page and when i click next, the 2nd page display the whole database content.

"FTsearchtable.php" it consist of while loop to get results to display in table. Can someone able to assist me? Thanks :)

$val_d = $_POST['device_search'];

if ($_POST['SEARCH'] = 'Device Search')
{
	$sql = "SELECT *
			FROM device
			WHERE device_num LIKE '%$val_d%' or '%$val_d'"; 
	$results1 = mysql_query($sql) or die (mysql_error());	
	
			$pagenum = $_GET["pagenum"];
			echo "<center>";
			//This checks to see if there is a page number. If not, it will set it to page 1 
			if (!(isset($pagenum))) 
			{ 
			$pagenum = 1; 
			} 

	$numrows = mysql_num_rows($results1);		
	$page_rows = 10; //This is the number of results displayed per page 
	$last = ceil($numrows/$page_rows); //This tells us the page number of our last page 
	if ($pagenum < 1) //this makes sure the page number isn't below one, or more than our maximum pages 
	{ 
	$pagenum = 1; 
	} 
	elseif ($pagenum > $last) 
	{ 
	$pagenum = $last; 
	} 

	$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This sets the range to display in our query 
				
	$sql = "SELECT *
			FROM device
			WHERE device_num LIKE '%$val_d%' or '%$val_d' $max"; 
	$results = mysql_query($sql) or die (mysql_error());
 
	$count = mysql_result($results,0,0);
	echo "<b></center>Record Count: </b> $count record(s)<br><br><center>";

	include "FTsearchtable.php";
	
	echo "<br><br><center>Page $pagenum of $last<br><br>"; // This shows the user what page they are on, and the total number of pages

	// First we check if we are on page one. 
	//If we are then we don't need a link to the previous page or the first page so we do nothing. 
	//If we aren't then we generate links to the first page, and to the previous page.
	if($pagenum>1)
	{

	echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=1'>First</a> ";
	$previous = $pagenum-1;
	echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>Previous</a> ";
	} 
	//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
	if ($pagenum == $last) 
	{
	} 
	else 
	{
	$next = $pagenum+1;
	echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next</a> ";
	echo " ";
	echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a> ";
	} 
	
	}

Edited by futhonguy: n/a

This question has already been answered. 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.