Russia Posted November 2, 2009 Share Posted November 2, 2009 <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include("inc/config.php"); if (!(isset($pagenum))); { $pagenum = 1; } $data = mysql_query("SELECT * FROM accounts") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { Print $info['username']; Print $info['password']; echo "<br>"; } echo "<p>"; echo " --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> "; } ?> Now for some reason it is not going to the next page. It is only showing the first 4 rows and it wont show the rest when I click the next or last button. Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted November 2, 2009 Share Posted November 2, 2009 Where exactly are you setting $pagenum? from what I see you only have an if test to see if it's set and set it to one if it isn't, which it will always be since you've not set it Quote Link to comment Share on other sites More sharing options...
JAY6390 Posted November 2, 2009 Share Posted November 2, 2009 You may also want to look into my php pagination class. It makes paginating results a breeze Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 2, 2009 Share Posted November 2, 2009 if (!(isset($pagenum))); { $pagenum = 1; } $pagenum is never defined before this code is run, therefore it will always get set to 1. Replace the above with this: $pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1; Quote Link to comment Share on other sites More sharing options...
Russia Posted November 2, 2009 Author Share Posted November 2, 2009 Thank You very much. It is now fixed. Quote Link to comment Share on other sites More sharing options...
Russia Posted November 2, 2009 Author Share Posted November 2, 2009 Thanks its fixed now: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include("inc/config.php"); $pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1; $data = mysql_query("SELECT * FROM accounts") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { echo "Username: "; Print $info['username']; echo "<br>"; echo "Password: "; Print $info['password']; echo "<br>----"; echo "<br>"; } echo "<p>"; echo " --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> "; } ?> ---- Now I need help with another thing, How would I do it so instead of it posting it like this when im at the first page: ---- Next -> Last ->> To like this: | 1 | 2 | 3| Last ->> Like it adds a number based on how many pages, its like instead of using the Next -> thing clicking over and over again to get to like page 5. Same thing with the rest of the pages: <<-First | 1 | 2 | 3| Last ->> And the last page: <<-First | 1 | 2 | 3| Does anyone know how to do this? I want number pages instead of clicking to get to the next page or the page before. Quote Link to comment Share on other sites More sharing options...
Russia Posted November 2, 2009 Author Share Posted November 2, 2009 Thanks its fixed now: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include("inc/config.php"); $pagenum = (isset($_GET['pagenum'])) ? (int) $_GET['pagenum'] : 1; $data = mysql_query("SELECT * FROM accounts") or die(mysql_error()); $rows = mysql_num_rows($data); $page_rows = 4; $last = ceil($rows/$page_rows); if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; $data_p = mysql_query("SELECT * FROM accounts $max") or die(mysql_error()); while($info = mysql_fetch_array( $data_p )) { echo "Username: "; Print $info['username']; echo "<br>"; echo "Password: "; Print $info['password']; echo "<br>----"; echo "<br>"; } echo "<p>"; echo " --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> "; } ?> ---- Now I need help with another thing, How would I do it so instead of it posting it like this when im at the first page: ---- Next -> Last ->> To like this: | 1 | 2 | 3| Last ->> Like it adds a number based on how many pages, its like instead of using the Next -> thing clicking over and over again to get to like page 5. Same thing with the rest of the pages: <<-First | 1 | 2 | 3| Last ->> And the last page: <<-First | 1 | 2 | 3| Does anyone know how to do this? I want number pages instead of clicking to get to the next page or the page before. Bumping. Quote Link to comment Share on other sites More sharing options...
Russia Posted November 2, 2009 Author Share Posted November 2, 2009 Anyone can help me out??? Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 2, 2009 Share Posted November 2, 2009 This is a separate problem. Your first problem has apparently been fixed. You should mark this thread as solved and open a new topic for the numbering issue. Quote Link to comment 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.