bugzy Posted July 17, 2012 Share Posted July 17, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/265861-pagination-now-working/ Share on other sites More sharing options...
scootstah Posted July 17, 2012 Share Posted July 17, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/265861-pagination-now-working/#findComment-1362303 Share on other sites More sharing options...
bugzy Posted July 17, 2012 Author Share Posted July 17, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/265861-pagination-now-working/#findComment-1362304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.