Daney11 Posted December 3, 2007 Share Posted December 3, 2007 Hey guys, having trouble with pagition. <?php include_once('settings.php'); // This Includes The Settings Of The Website include_once('functions.php'); // This Includes The Functions Of The Website include_once('team.php'); // This Includes The Team Information Of The Website include_once('bbcode.php'); // This Includes The Team Information Of The Website // START PAGITION if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $data = mysql_query("SELECT * FROM coverage WHERE coverage_teamid = '$team_url'") or die(mysql_error()); $rows = mysql_num_rows($data); //This is the number of results displayed per page $page_rows = 1; //This tells us the page number of our last page $last = ceil($rows/$page_rows); //this makes sure the page number isn't below one, or more than our maximum pages if ($pagenum < 1) { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } //This sets the range to display in our query $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This is your query again, the same one... the only difference is we add $max into it $data_p = mysql_query("SELECT * FROM coverage WHERE coverage_teamid = $team_url ORDER BY `coverage_id` DESC") or die(mysql_error()); //This is where you display your query results while($coveragerow = mysql_fetch_array( $data_p )) { $coverage_id = escape_data($coveragerow['coverage_id']); $coverage_teamid = escape_data($coveragerow['coverage_teamid']); $coverage_title = escape_data($coveragerow['coverage_title']); $coverage_image = escape_data($coveragerow['coverage_image']); $coverage_body = $coveragerow['coverage_body']; $coverage_author = escape_data($coveragerow['coverage_author']); $coverage_date = escape_data($coveragerow['coverage_date']); // Check If The Team URL Is Correct if ($coverage_teamid == $team_url) { // Include Layout For Team include_once('header.php'); // This Includes The Header Of The Website Layout include("layouts/".$team_layout."/coverage.php"); } // End If Statement // If Team URL Is Not Correct, Direct To Main URL else { // Start Else Statement // PHP SELF Re-directs To Main URL header('Location: '.$_SERVER['PHP SELF'].''); } // End Else Statement } // This shows the user what page they are on, and the total number of pages echo "<table class=\"resultstable\"><tr><td>Page $pagenum of $last</td>"; // 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> "; } //just a spacer //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 " <td><a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next</a></td> "; echo " "; echo " <td><a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last</a></td></table> "; } // END PAGITION include_once('footer.php'); // This Includes The Footer Of The Website Layout ?> It works however. At the bottom im getting Page 1 of 2, and when i click next to goto 2, it still says page 1 of 2 and shows the 2 entrys in my database. Ive limited the max entrys on 1 page to 1, so i should get the next entry on the next page. But it doesnt work, it shows both entrys on the one page. Any ideas? Thanks Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 3, 2007 Share Posted December 3, 2007 Does $pagenum get set in one of your included files? If so, could you post that code, please? Quote Link to comment Share on other sites More sharing options...
Daney11 Posted December 3, 2007 Author Share Posted December 3, 2007 no it doesnt, it gets set here if (!(isset($pagenum))) { $pagenum = 1; } top of page Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 3, 2007 Share Posted December 3, 2007 $pagenum will always get set to 1, then because you aren't getting it from anywhere. Make sure that you are actually passing the variable to this file. In which case, you will need to use something like $_GET['pagenum'] or $_POST['pagenum'], depending on how you are passing the variable. GET would make more sense, so the link should include a "?pagenum=1" or something. 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.