Posted By

jamepaul on 08/05/10


Tagged

php pagination


Versions (?)

Who likes this?

6 people have marked this snippet as a favorite

jfherring
joacoleo
stamba
neex123
riacharda
dmanjdb


Pagination


 / Published in: PHP
 

  1. <?php include('config.php');
  2. $query = "SELECT * FROM table_name";
  3. $result = mysql_query($query);
  4. $total_record = mysql_num_rows($result);
  5.  
  6. $show = 5; // Number of record that want to show
  7.  
  8. if ( isset($_GET['start']) ) {
  9. $start = $_GET['start'];
  10. } else {
  11. $start = 0;
  12. }
  13.  
  14. $query = "SELECT * FROM table_name ORDER BY id DESC LIMIT $start, $show";
  15. $result = mysql_query($query);
  16.  
  17. if ( !empty($total_record) ) {
  18. $num1 = $total_record / $show;
  19. $num1 = intval($num1);
  20. if ( $total_record % $show != 0 ) $num1 += 1;
  21. for ( $i=0; $i < $num1; $i++ ) {
  22. $j = $i * $show;
  23. $pagenum = $i + 1;
  24.  
  25. if( empty($_GET['curr']) ) $_GET['curr'] = 1;
  26.  
  27. $current = $_GET['curr'] == $pagenum ? "current" : NULL;
  28. $curr = $pagenum;
  29. $pagnav .= '<li class="clearfix"><a class="';
  30. $pagnav .= $current . '" href="?start=' . $j . '&&curr=' . $curr . '">' . $pagenum . '</li></a>';
  31. } // end for
  32. echo "<ul>" . $pagnav . "</ul>";
  33. } // end if
  34. ?>

Report this snippet  

You need to login to post a comment.