944,183 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 1611
  • PHP RSS
Nov 9th, 2007
0

Pagination Help

Expand Post »
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:

PHP Syntax (Toggle Plain Text)
  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. ?>
Similar Threads
Reputation Points: 18
Solved Threads: 16
Junior Poster
ivatanako is offline Offline
150 posts
since Jul 2007
Nov 10th, 2007
0

Re: Pagination Help

is there any errors? what exactly is happening?
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Nov 10th, 2007
0

Re: Pagination Help

if (!isset($pagenum))
{
.....
}




save a bit
php Syntax (Toggle Plain Text)
  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> ";
}
Reputation Points: 6
Solved Threads: 19
Posting Whiz in Training
fatihpiristine is offline Offline
283 posts
since Sep 2007
Nov 10th, 2007
0

Re: Pagination Help

Click to Expand / Collapse  Quote originally posted by kkeith29 ...
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.
Reputation Points: 18
Solved Threads: 16
Junior Poster
ivatanako is offline Offline
150 posts
since Jul 2007
Nov 10th, 2007
0

Re: Pagination Help

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.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Nov 10th, 2007
0

Re: Pagination Help

Click to Expand / Collapse  Quote originally posted by kkeith29 ...
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.
Reputation Points: 18
Solved Threads: 16
Junior Poster
ivatanako is offline Offline
150 posts
since Jul 2007
Nov 10th, 2007
0

Re: Pagination Help

can you give me the url of the page so i can see what is happening for myself.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Nov 11th, 2007
0

Re: Pagination Help

Click to Expand / Collapse  Quote originally posted by kkeith29 ...
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.
Reputation Points: 18
Solved Threads: 16
Junior Poster
ivatanako is offline Offline
150 posts
since Jul 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: doc root in windows virtual hosting
Next Thread in PHP Forum Timeline: Send message





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC