ankit.pandeyc012 Posted November 25, 2010 Share Posted November 25, 2010 <?php require_once('upper.php'); // Connects to your Database require_once('database.php'); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } //Here we count the number of results //Edit $data to be your query $query = "SELECT * FROM events"; $result = mysqli_query($dbc,$query) or die('Not'); $rows = mysqli_num_rows($result); //This is the number of results displayed per page $page_rows = 2; //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 range that we will 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 $result = mysqli_query($dbc,"SELECT * FROM events $max") or die('Not'); //This is where you display your query results while($row = mysqli_fetch_array( $result)) { $Title=$row['Title']; $City=$row['City']; $Content=$row['Content']; //$Photo=$row['Photo']; $Date=$row['Date']; $EventId=$row['EventId']; $Photo=$row['Photo']; //echo $Photo; echo "<div><table border='0' cellspacing='0' cellpadding='0' width='389'> <tr> <td><img src='images/events_2.png' width='389' height='10'></td> </tr> <tr> <td background='images/events_2_bg.png'> <table border='0' cellspacing='0' width='359'> <tr> <td> <tr> <table width='100%' border='0' cellspacing='0' > <tr> <td rowspan='3'><img src='$Photo' width='80' height='60'></td> <td align='left' valign='top' width='180'>$City</td> <td align='left' valign='top'>$Date</td> </tr> <tr> <td colspan='3' align='left' valign='top'>$Title</td> </tr> <tr> <td colspan='2'><a href='KnowMore.php?EventId=".$row['EventId']."'>Know more </a> / <a href='EventParticipator.php?EventId=".$row['EventId']."'>click here to participate</a></td> </tr> </table> </tr> </tr> </table> </td> </tr> <tr> <td><img src='images/events_2_bottom.png' width='389' height='10' ></td> </tr> </table></div>"; } echo "<p>"; // This shows the user what page they are on, and the total number of pages echo " --Page $pagenum of $last-- <p>"; // 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['pagination.php']}?pagenum=1'> <<-First</a> "; echo " "; $previous = $pagenum-1; echo " <a href='{$_SERVER['page_test.php']}?pagenum=$previous'> <-Previous</a> "; } echo $PHP_SELF; //just a spacer echo " ---- "; //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['page_test.php']}?pagenum=$next'>Next -></a> "; echo " "; echo " <a href='{$_SERVER['page_test.php']}?pagenum=$last'>Last ->></a> "; } require_once('lower.php'); ?> Hi friends............ I want to paginate my page but it not works properly. It displays first 2 rows but on clicking "Next" nothing happens. It displays error also "Notice: Undefined variable: PHP_SELF in C:\wamp\www\NGOProject\Elite Brigade\pagination.php on line 112" and "Notice: Undefined index: page_test.php in C:\wamp\www\NGOProject\Elite Brigade\pagination.php on line 124"......... I don't know what to do?????? Plz help me anyone??????? Quote Link to comment Share on other sites More sharing options...
seanlim Posted November 25, 2010 Share Posted November 25, 2010 Work on your semantic errors before the logic errors (if any). The first error tell you that you don't have a variable called "PHP_SELF" defined. You probably want $_SERVER['PHP_SELF']. The second error tells you that $_SERVER['page_test.php'] does not exist, although $_SERVER definitely does. To see the valid keys for the $_SERVER predefined variable, read through the documentation here: http://www.php.net/manual/en/reserved.variables.server.php Quote Link to comment Share on other sites More sharing options...
ankit.pandeyc012 Posted November 25, 2010 Author Share Posted November 25, 2010 Boss I remove the syntax errors........but by commenting the PHP_SELF variable. But logical errors remain still same......... Quote Link to comment Share on other sites More sharing options...
seanlim Posted November 25, 2010 Share Posted November 25, 2010 the logic seems correct. check the links (view-source), make sure that they are properly formatted and links you back to the same script. and please don't say it doesn't work without giving any description of your errors. what logic errors are you getting? page not showing? links not showing? when do they happen? after clicking which link? Quote Link to comment Share on other sites More sharing options...
ankit.pandeyc012 Posted November 25, 2010 Author Share Posted November 25, 2010 It displays first page well but the problem is on click "Next" or "Last" button nothing happens which I also mentioned in my quote............ Plz help............ Quote Link to comment Share on other sites More sharing options...
seanlim Posted November 25, 2010 Share Posted November 25, 2010 read my full message: the logic seems correct. check the links (view-source), make sure that they are properly formatted and links you back to the same script. what about that? are the links okay? i would help if you follow the suggestions provided and then provide your feedback on what happens when you try them. in this case, it would help if you tell me whether the links aren't malformed and whether there are any errors generated in the links. Quote Link to comment Share on other sites More sharing options...
ankit.pandeyc012 Posted November 25, 2010 Author Share Posted November 25, 2010 Dear I am not sure what you want to say??? On click any link same page refresh instead of showing next page..... I think it is very little mistake which we not able to find...... Plz see the code and suggest something............. Quote Link to comment Share on other sites More sharing options...
raymonn23 Posted November 25, 2010 Share Posted November 25, 2010 Try this links http://einchi.com/2008/08/11/paging-with-php-part3/ http://www.plus2net.com/php_tutorial/php_paging.php http://articles.sitepoint.com/article/php-paging-result-sets/ Quote Link to comment Share on other sites More sharing options...
seanlim Posted November 25, 2010 Share Posted November 25, 2010 as i've said, your script looks logical. and there isn't anything wrong with it, assuming you've correctly fixed the previously mentioned errors. okay, i'll make this really simple 1. LOAD the page 2. VIEW-source 3. LOOK at all the href attributes of the links i.e. <a> elements. what do you see? is it "your_script_name.php?pagenum=2"? 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.