PHP Pagination reloaded problem

Discussion in 'Web Design & Coding' started by simy202, Jan 24, 2011.

  1. simy202

    simy202

    Joined:
    Jan 24, 2011
    Messages:
    1
    Likes Received:
    0
    Location:
    United States
    I am extracting values from database and want to display them. However, since the results are huge, so I've done pagination by scripts on phpkode.com/scripts/tag/pagination/. The first page works well, while when I clicked on the 2nd page, the page gets reloaded and no results are displayed. I failed to figure out what's wrong with my coding,

    the pagination code is placed in a seperate file named functions.php as below:

    Code:
       1. function build_url($filename, $key, $value){
       2.   $values = array();
       3.   $query_str = array();
       4.   parse_str($_SERVER['QUERY_STRING'], $values);
       5.   foreach ($values as $k=>$v) {
       6.     if ($k!=$key) {
       7.       $query_str[] = "{$k}={$v}";
       8.     }
       9.   }
      10.   $query_str[] = "{$key}={$value}";
      11.   return "$filename?".implode("&", $query_str);
      12. }
      13.  
      14. //paging script
      15. function pagingScript($filename, $page_num, $numofpages) {
      16.     $range = 20;
      17.     $range_min = ($range % 2 == 0) ? ($range / 2) - 1 : ($range - 1) / 2;
      18.     $range_max = ($range % 2 == 0) ? $range_min + 1 : $range_min;
      19.     $page_min = $page_num- $range_min;
      20.     $page_max = $page_num+ $range_max;
      21.  
      22.     $page_min = ($page_min < 1) ? 1 : $page_min;
      23.     $page_max = ($page_max < ($page_min + $range - 1)) ? $page_min + $range - 1 : $page_max;
      24.     if ($page_max > $numofpages) {
      25.         $page_min = ($page_min > 1) ? $numofpages - $range + 1 : 1;
      26.         $page_max = $numofpages;
      27.     }
      28.  
      29.     $page_min = ($page_min < 1) ? 1 : $page_min;
      30.  
      31.     $page_pagination .= "<br /><table align='center' width='100%'><tr><td align='left' width='10%'>";
      32.     if ( ($page_num > ($range - $range_min)) && ($numofpages > $range) ) {
      33.         $page_pagination .= '<a title="First" href="'.build_url($filename, "page", 1).'">&lt;&lt;</a> ';
      34.     }
      35.     if ($page_num != 1) {
      36.         $page_pagination .= '<a href="'.build_url($filename, "page", $page_num-1).'">Previous</a> ';
      37.     }
      38.     $page_pagination .= "</td><td align='center' width='80%'>";
      39.  
      40.     for ($i = $page_min;$i <= $page_max;$i++) {
      41.         if ($i == $page_num)
      42.             $page_pagination .= '<b>' . $i . '</b> &nbsp; ';
      43.         else
      44.             $page_pagination.= '<a href="'.build_url($filename, "page", $i).'">'.$i.'</a> &nbsp; ';
      45.     }
      46.  
      47.     $page_pagination .= "</td><td  align='right' width='10%'>";
      48.     if ($page_num < $numofpages) {
      49.         $page_pagination.= ' <a href="'.build_url($filename, "page", $page_num+1).'">Next</a>';
      50.     }
      51.     if (($page_num< ($numofpages - $range_max)) && ($numofpages > $range)) {
      52.         $page_pagination .= ' <a title="Last" href="'.build_url($filename, "page", $numofpages).'">&gt;&gt;</a> ';
      53.     }
      54.     $page_pagination .= "</td></tr></table><br />";
      55.  
      56.     echo $page_pagination;
      57. }
      58.  
      59.  
      60.  
    Thanks for any help.
     
    simy202, Jan 24, 2011
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SwordWielder

    PHP?

    SwordWielder, Mar 23, 2003, in forum: Web Design & Coding
    Replies:
    2
    Views:
    1,330
    SwordWielder
    Mar 24, 2003
  2. James

    Final Matrix Reloaded trailer!

    James, Apr 11, 2003, in forum: Books, Movies, TV and music
    Replies:
    10
    Views:
    1,918
    SwordWielder
    Aug 31, 2003
  3. Josh

    Learn PHP in 24 hrs

    Josh, May 20, 2003, in forum: Web Design & Coding
    Replies:
    6
    Views:
    1,645
    lam3r
    Aug 16, 2003
  4. boxrick

    Making website in php, where to start?

    boxrick, Oct 14, 2003, in forum: Web Design & Coding
    Replies:
    1
    Views:
    1,398
    wordless
    Oct 22, 2003
  5. JMorris

    VbHome VS. PHP-Nuke

    JMorris, Dec 18, 2003, in forum: Software
    Replies:
    1
    Views:
    858
    JMorris
    Dec 18, 2003
  6. James
    Replies:
    2
    Views:
    1,309
    James
    Feb 14, 2004
  7. undeadpenguin

    MySQL/PHP Job/Tutorial

    undeadpenguin, Apr 7, 2004, in forum: Web Design & Coding
    Replies:
    1
    Views:
    1,146
    James
    Apr 12, 2004
  8. The Doctor

    MS Word Pagination problem solved

    The Doctor, Aug 15, 2005, in forum: Computing
    Replies:
    4
    Views:
    1,457
    Rod Speed
    Aug 19, 2005
Loading...