Jump to content

pagination now working


bugzy

Recommended Posts



if(!isset($pagenum))
{
$pagenum = 1;
}


$page_query = "Select item_id from item";

$page_result = mysql_query($page_query,$connection);

$page_num_rows = mysql_num_rows($page_result);


$page_rows = 10;


$last = ceil($page_num_rows/$page_rows);


if($pagenum < 1)
{
$pagenum = 1;
}
else if($pagenum > $last)
{
$pagenum = $last;
}


$max = 'limit '. ($pagenum - 1) * $page_rows . ',' . $page_rows;




$query = "Select item_id, item_code, item_price, item_stock, item_sale, item_reg from item $max";

$result = mysql_query($query,$connection);

$num = mysql_num_rows($result);


//This is where I display my query results




echo "<p> --Page {$pagenum} of {$last}-- <p>";



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> ";

} 


echo " ---- ";

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> ";

} 




 

 

 

At first it will show the 1st 10 rows but when I click next or last I'm still getting only the 1st 10 rows..

 

Anyone?

Link to comment
https://forums.phpfreaks.com/topic/265861-pagination-now-working/
Share on other sites

You are never retrieving the pagenum from the querystring.

 

if(!isset($pagenum))
{
        $pagenum = 1;
}

 

I'm assuming this snippet is relying on register_globals to be enabled. It should be changed to:

if(isset($_GET['pagenum'])) {
$pagenum = (int) $_GET['pagenum'];
} else {
$pagenum = 1;
}

You are never retrieving the pagenum from the querystring.

 

if(!isset($pagenum))
{
        $pagenum = 1;
}

 

I'm assuming this snippet is relying on register_globals to be enabled. It should be changed to:

if(isset($_GET['pagenum'])) {
$pagenum = (int) $_GET['pagenum'];
} else {
$pagenum = 1;
}

 

Thanks again  ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.