Pagination Help

Thread Solved

Join Date: Jul 2007
Posts: 77
Reputation: ivatanako is an unknown quantity at this point 
Solved Threads: 5
ivatanako ivatanako is offline Offline
Junior Poster in Training

Pagination Help

 
0
  #1
Nov 9th, 2007
I needed to paginate my article section at my site so that i wont have 20 paragraphs page, now when I tried this on LOCALHOST i encountered no problem at all. But when I uploaded it on my server, the pagination doesn't work. I think the problem here is about the global variables, but im not sure and I dont know how to fix it. Here's my code:

  1. <?php
  2. $pagenum = $_GET['pagenum'];
  3. $pagetitle = 'article Sections';
  4. $active = '2';
  5. include('../includes/header.php');
  6. $dbcnt = mysql_connect("localhost", "xxxxxx", "xxxxx");
  7. mysql_select_db("articles");
  8.  
  9. echo '<!-- content-wrap starts here -->
  10. <div id="content-wrap"> ';
  11. include('../includes/sidebar.php');
  12. echo '<div id="main">';
  13. //This checks to see if there is a page number. If not, it will set it to page 1
  14. if (!(isset($pagenum)))
  15. {
  16. $pagenum = 1;
  17. }
  18.  
  19. //Here we count the number of results
  20. //Edit $data to be your query
  21.  
  22. $data = mysql_query("SELECT * FROM dlink");
  23. $rows = mysql_num_rows($data);
  24.  
  25. //This is the number of results displayed per page
  26. $page_rows = 4;
  27.  
  28. //This tells us the page number of our last page
  29. $last = ceil($rows/$page_rows);
  30.  
  31. //this makes sure the page number isn't below one, or more than our maximum pages
  32. if ($pagenum < 1)
  33. {
  34. $pagenum = 1;
  35. }
  36. elseif ($pagenum > $last)
  37. {
  38. $pagenum = $last;
  39. }
  40.  
  41. $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
  42. //This is your query again, the same one... the only difference is we add $max into it
  43. $data_p = mysql_query("SELECT * FROM dlink $max") or die(mysql_error());
  44. // Query the database
  45. while ($row = mysql_fetch_assoc($data_p)) {
  46. echo '<div class="box">';
  47. echo '<h1>' .$row['downName'].'</h1>';
  48. echo '<p>Added on: <cite>'.$row['downTime'].'<cite></p>';
  49. echo '<img src='.$row['downImg'].' width=140 height=110 class="dimg" /><p style="text-indent:1px;">'.$row['downDes'].'</p>';
  50. echo '<br clear=none/><p class=comments align-right>Download link:<a href='.$row['downLink'].' target="_self">Download link</a></p>';
  51. echo '</div><div class="boxBottom"><img src="http://ivatanako.000webhost.info/images/block-bottom-bg.jpg" alt=""></div>';
  52. }
  53. echo '<div class="box"><p class=comments align-right>';
  54.  
  55. // This shows the user what page they are on, and the total number of pages
  56. echo " Page $pagenum of $last ";
  57.  
  58. // 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.
  59. if ($pagenum == 1)
  60. {
  61. }
  62. else
  63. {
  64. echo " <a href='index.php?pagenum=1'> <<-First</a> ";
  65. echo " ";
  66. $previous = $pagenum-1;
  67. echo " <a href='index.php?pagenum=$previous'> <-Previous</a> ";
  68. }
  69.  
  70.  
  71. //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
  72. if ($pagenum == $last)
  73. {
  74. }
  75. else {
  76. $next = $pagenum+1;
  77. echo " <a href='index.php?pagenum=$next'>Next -></a> ";
  78. echo " ";
  79. echo " <a href='index.php?pagenum=$last'>Last ->></a> ";
  80. }
  81. echo '</div><div class="boxBottom"><img src="http://xxx.com/images/block-bottom-bg.jpg" alt=""></div>';
  82. // end all div
  83. echo '</div></div>';
  84. include('../includes/footer.php');
  85. ?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Pagination Help

 
0
  #2
Nov 10th, 2007
is there any errors? what exactly is happening?
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 271
Reputation: fatihpiristine has a little shameless behaviour in the past 
Solved Threads: 16
fatihpiristine's Avatar
fatihpiristine fatihpiristine is offline Offline
Posting Whiz in Training

Re: Pagination Help

 
0
  #3
Nov 10th, 2007
if (!isset($pagenum))
{
.....
}




save a bit
  1.  
  2. if ($pagenum != 1)
  3. {
  4. echo " <a href='index.php?pagenum=1'> <<-First</a> ";
  5. echo " ";
$previous = $pagenum-1;
echo " <a href='index.php?pagenum=$previous'> <-Previous</a> ";
}
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 77
Reputation: ivatanako is an unknown quantity at this point 
Solved Threads: 5
ivatanako ivatanako is offline Offline
Junior Poster in Training

Re: Pagination Help

 
0
  #4
Nov 10th, 2007
Originally Posted by kkeith29 View Post
is there any errors? what exactly is happening?
The problem is, is that the second page is not showing. The code works well on testing at localhost but when i uploaded it on webserver, it doesnt work.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Pagination Help

 
0
  #5
Nov 10th, 2007
is the url changing when a next or prev link is pressed? is the script outputting the right numbers to the next and prev links? i copied the script, made a few minor changes (mysql connect info, table names, ect..) so it would work for me, and i had no problems with it.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 77
Reputation: ivatanako is an unknown quantity at this point 
Solved Threads: 5
ivatanako ivatanako is offline Offline
Junior Poster in Training

Re: Pagination Help

 
0
  #6
Nov 10th, 2007
Originally Posted by kkeith29 View Post
is the url changing when a next or prev link is pressed? is the script outputting the right numbers to the next and prev links? i copied the script, made a few minor changes (mysql connect info, table names, ect..) so it would work for me, and i had no problems with it.
It is changing, it was also working on localhost, I just dont know why doesn't it work on my website.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Pagination Help

 
0
  #7
Nov 10th, 2007
can you give me the url of the page so i can see what is happening for myself.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 77
Reputation: ivatanako is an unknown quantity at this point 
Solved Threads: 5
ivatanako ivatanako is offline Offline
Junior Poster in Training

Re: Pagination Help

 
0
  #8
Nov 11th, 2007
Originally Posted by kkeith29 View Post
can you give me the url of the page so i can see what is happening for myself.
Thank you for the time. I was able to fix it by rewriting the whole code.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC