Have an account? Sign in
Login  Register  Facebook
2nd page shown no result after pagination?
I am extracting values from database and want to display them. However, since the results are huge, so I've done PHP 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:

 function build_url($filename, $key, $value){
   $values = array();
   $query_str = array();
   parse_str($_SERVER['QUERY_STRING'], $values);
   foreach ($values as $k=>$v) {
     if ($k!=$key) {
       $query_str[] = "{$k}={$v}";
     }
   }
   $query_str[] = "{$key}={$value}";
   return "$filename?".implode("&", $query_str);
 }
  
 //paging script
 function pagingScript($filename, $page_num, $numofpages) {
     $range = 20;
     $range_min = ($range % 2 == 0) ? ($range / 2) - 1 : ($range - 1) / 2;
     $range_max = ($range % 2 == 0) ? $range_min + 1 : $range_min;
     $page_min = $page_num- $range_min;
     $page_max = $page_num+ $range_max;
  
     $page_min = ($page_min < 1) ? 1 : $page_min;
     $page_max = ($page_max < ($page_min + $range - 1)) ? $page_min + $range - 1 : $page_max;
     if ($page_max > $numofpages) {
         $page_min = ($page_min > 1) ? $numofpages - $range + 1 : 1;
         $page_max = $numofpages;
     }
  
     $page_min = ($page_min < 1) ? 1 : $page_min;
  
     $page_pagination .= "<br /><table align='center' width='100%'><tr><td align='left' width='10%'>";
     if ( ($page_num > ($range - $range_min)) && ($numofpages > $range) ) {
         $page_pagination .= '<a title="First" href="'.build_url($filename, "page", 1).'"><<</a> ';
     }
     if ($page_num != 1) {
         $page_pagination .= '<a href="'.build_url($filename, "page", $page_num-1).'">Previous</a> ';
     }
     $page_pagination .= "</td><td align='center' width='80%'>";
  
     for ($i = $page_min;$i <= $page_max;$i++) {
         if ($i == $page_num)
             $page_pagination .= '<b>' . $i . '</b>   ';
         else
             $page_pagination.= '<a href="'.build_url($filename, "page", $i).'">'.$i.'</a>   ';
     }
  
     $page_pagination .= "</td><td  align='right' width='10%'>";
     if ($page_num < $numofpages) {
         $page_pagination.= ' <a href="'.build_url($filename, "page", $page_num+1).'">Next</a>';
     }
     if (($page_num< ($numofpages - $range_max)) && ($numofpages > $range)) {
         $page_pagination .= ' <a title="Last" href="'.build_url($filename, "page", $numofpages).'">>></a> ';
     }
     $page_pagination .= "</td></tr></table><br />";
  
     echo $page_pagination;
 }



Thanks for any help.
Started: September 22, 2011 Latest Activity: September 22, 2011 pagination

Could you provide an example of your $_SERVER['QUERY_STRING'] or output of your build_url. It would be easier to see what is going on
September 22, 2011

1 Answer
what about using this code:How To Create A Pagination In PHP

Posted: MacOS
In: September 22, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer