Advertisement
ekoekaeko

pagination

Aug 18th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 4.45 KB | None | 0 0
  1. <link href='../css/icon.css' type='text/css' rel='stylesheet' />
  2.  <script type="text/javascript">
  3.  
  4.   function pilihan()
  5.   {
  6.      // membaca jumlah komponen dalam form bernama 'myform'
  7.      var jumKomponen = document.myform.length;
  8.  
  9.      // jika checkbox 'Pilih Semua' dipilih
  10.      if (document.myform[0].checked == true)
  11.      {
  12.         // semua checkbox pada data akan terpilih
  13.         for (i=1; i<=jumKomponen; i++)
  14.         {
  15.             if (document.myform[i].type == "checkbox") document.myform[i].checked = true;
  16.         }
  17.      }
  18.      // jika checkbox 'Pilih Semua' tidak dipilih
  19.      else if (document.myform[0].checked == false)
  20.         {
  21.             // semua checkbox pada data tidak dipilih
  22.             for (i=1; i<=jumKomponen; i++)
  23.             {
  24.                if (document.myform[i].type == "checkbox") document.myform[i].checked = false;
  25.             }
  26.         }
  27.   }
  28.  
  29. </script>
  30. <h3 align="center">Data Anggota</h3>
  31.         <?php echo "<form name='myform' method='POST' action='include/deleteloker.php'>";
  32.        
  33.         echo "<tr><td background='red'><input type='checkbox' name='pilih' onclick='pilihan()' /> </td>";?><input type="submit" class="btn btn-danger" value="Antrikan"  onClick="return warning();" name="submit"></a>
  34.        
  35.         <a href='?module=data-antrian-loker'><input type="button" class="btn btn-danger" value="Daftar Antrian"  name="print"></a>
  36.         <a href='include/prosesbarcode.php' target="_blank"><input type="button" class="btn btn-danger" value="Print"  name="print"></a><br><br>
  37.    
  38. <?php
  39.  
  40. include '../koneksi.php';
  41. // jumlah data yang akan ditampilkan per halaman
  42.  
  43. $dataPerPage = 10;
  44.  
  45. // apabila $_GET['page'] sudah didefinisikan, gunakan nomor halaman tersebut,
  46. // sedangkan apabila belum, nomor halamannya 1.
  47.  
  48. if(isset($_GET['page']))
  49. {
  50.     $noPage = $_GET['page'];
  51. }
  52. else $noPage = 1;
  53.  
  54. // perhitungan offset
  55.  
  56. $offset = ($noPage - 1) * $dataPerPage;
  57.  
  58. // query SQL untuk menampilkan data perhalaman sesuai offset
  59.  
  60. $query = "SELECT * FROM loker LIMIT $offset, $dataPerPage";
  61.  
  62. $result = mysql_query($query) or die('Error');
  63.  
  64. // menampilkan data
  65.  
  66. ?>
  67. <table cellpadding="0" cellspacing="0" border="1" class="display" id="example">
  68.     <thead>
  69.         <tr>
  70.             <th width="10px">Pilih</th><th width="10px">No</th><th >Nama</th><th >Alamat</th>
  71.            
  72.             <th>Edit</th><th>Delete</th>
  73.         </tr>  
  74.     </thead>
  75.     <tbody><?php
  76.    
  77.    
  78.    
  79. while($data = mysql_fetch_array($result))
  80. {
  81.   ?>
  82.   <tr class="odd graaadeX">
  83.             <td><input type="checkbox" name="id[<?php echo $i;?>]" value="<?php echo $data['id'];?>" />
  84.             </td><td valign="top" width="10px"> <?php $i++; echo $j+1;?> </td> 
  85.        
  86.             <td valign="top" > <?php echo $data["loker"];?></td>
  87.             <td valign="top" > <?php echo $data["alamat"];?></td>
  88.  
  89.            
  90.                
  91.            
  92.            
  93.            
  94.            
  95.            
  96.             <td valign="top" class="center"><?php  echo "<a href='?module=edit-loker&id=".$data['id']."'><i class='icon-edit'></i> </a>
  97.             </td>";?><td valign="top" class="center"><?php  echo "<a href='?module=hapus-loker&id=".$data['id']."'><i class='icon-trash'></i> </a>
  98.  
  99.             </td>";?>
  100.            
  101.         </tr><?php $j++; ?>
  102.        
  103.             <?php  }
  104.             ?>
  105.  
  106.             <?php
  107. echo" <link href='../css/datables/demo_page.css' type='text/css' rel='stylesheet' />
  108.         <link href='../css/datables/demo_table.css' type='text/css' rel='stylesheet' />
  109. ";          ?>
  110.        
  111.     </tbody>
  112.    
  113.     </table><?php
  114.  
  115.  
  116.  
  117.  
  118. echo "</table>";
  119.  
  120. // mencari jumlah semua data dalam tabel guestbook
  121.  
  122. $query   = "SELECT COUNT(*) AS jumData FROM loker";
  123. $hasil  = mysql_query($query);
  124. $data     = mysql_fetch_array($hasil);
  125.  
  126. $jumData = $data['jumData'];
  127.  
  128. // menentukan jumlah halaman yang muncul berdasarkan jumlah semua data
  129.  
  130. $jumPage = ceil($jumData/$dataPerPage);
  131.  
  132. // menampilkan link previous
  133.  
  134. if ($noPage > 1) echo  "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage-1)."'>&lt;&lt; Prev</a>";
  135.  
  136. // memunculkan nomor halaman dan linknya
  137.  
  138. for($page = 1; $page <= $jumPage; $page++)
  139. {
  140.          if ((($page >= $noPage - 3) && ($page <= $noPage + 3)) || ($page == 1) || ($page == $jumPage))
  141.          {
  142.             if (($showPage == 1) && ($page != 2))  echo "...";
  143.             if (($showPage != ($jumPage - 1)) && ($page == $jumPage))  echo "...";
  144.             if ($page == $noPage) echo " <b>".$page."</b> ";
  145.             else echo " <a href='".$_SERVER['PHP_SELF']."?page=".$page."'>".$page."</a> ";
  146.             $showPage = $page;
  147.          }
  148. }
  149.  
  150. // menampilkan link next
  151.  
  152. if ($noPage < $jumPage) echo "<a href='".$_SERVER['PHP_SELF']."?page=".($noPage+1)."'>Next &gt;&gt;</a>";
  153.  
  154. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement