Advertisement
wzislam

PHP Pagination

Oct 1st, 2013
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.69 KB | None | 0 0
  1. <?php
  2. $showPage = 20;
  3. $pageNo = 1;
  4. if(isset($_GET['page']) && $_GET['page']!=1) {
  5.    
  6.     $pageNo=$_GET['page'];
  7.     $up = $showPage;
  8.     $low=$showPage*($_GET['page']-1);
  9.    
  10. } else {
  11.        
  12.     $up = $showPage;
  13.     $low=0;
  14.    
  15. } //endif(isset($_GET['page'])
  16.  
  17. $i=1;
  18. $sql2=("SELECT * FROM customers ORDER BY id DESC");
  19. $result2=mysql_query($sql2) or die (mysql_error());
  20. $count_row=mysql_num_rows($result2);//for pagination only
  21.  
  22. $customerList = mysql_query("SELECT * FROM customers ORDER BY id DESC LIMIT $low,$up") or die(mysql_error());
  23.  
  24. while( $customerArr = mysql_fetch_array($customerList) ) { ?>
  25.     TABLE HERE
  26. <?php } //while( $customerArr = mysql_fetch_array($customerList) ?>
  27.  
  28. <?php if($count_row!=""){ ?>
  29.  
  30.     <div class="paging">
  31.    
  32.         <?php if ($pageNo!=1){ ?>
  33.             <span class="prev"><a rel="prev" href="accessories.php?page=<?php echo $_GET['page']-1;?>">« Previous</a></span>
  34.         <?php } else { ?>
  35.             <span class="disabled">« Previous</span>
  36.         <?php } //endif ($pageNo!=1) ?>
  37.  
  38.         <?php
  39.         $pageCount = ceil($count_row/$showPage);
  40.         //echo $pageCount;
  41.         for ($i=1;$i<=$pageCount;$i++){
  42.    
  43.             if ($i == $pageNo){
  44.                
  45.                 echo "<span class=\"current\">"; echo $i; echo"</span>";
  46.                
  47.             } else { ?>
  48.            
  49.                 <span><a href="add_customer.php?page=<?php echo $i; ?>"><?php echo $i; ?></a></span>
  50.                
  51.             <?php } //endif ($i == $pageNo)
  52.            
  53.         } //end of for ($i=1;$i<=$pageCount;$i++) ?>
  54.    
  55.         <?php if ($pageCount!=$pageNo){ ?>
  56.             <span class="next"><a rel="next" href="add_customer.php?page=<?php echo $pageNo+1; ?>">Next »</a></span>
  57.         <?php } else {?>
  58.             <span class="disabled">Next »</span>
  59.         <?php } //if ($pageCount!=$pageNo) ?>
  60.  
  61.     </div> <!-- .paging -->
  62.    
  63. <?php } //endif($count_row!="") ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement