Advertisement
cdsatrian

paging

Feb 14th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.18 KB | None | 0 0
  1. echo "<h2 class='head'>DATA KARYAWAN</h2>
  2.     <table>
  3.     <td>
  4.     <div>
  5.     <input type=button value='Tambah Data' onclick=\"window.location.href='?module=pegawai&act=input';\">
  6.     </div>
  7.     </td>  
  8.     </table>
  9.     <table class='tabel'>
  10.     <thead>
  11.  <tr>
  12.    <td><center>No.</center></td>
  13.    <td><center>NIK</center></td>
  14.    <td><center>Nama Lengkap</center></td>
  15.     <td><center>Tanggal Masuk</center></td>
  16.     <td><center>Bagian</center></td>
  17.     <td><center>Jabatan</center></td>
  18.     <td><center>Control</center></td>
  19.  </tr>
  20.  </thead>";
  21.   $batas = 15;
  22.   $pg = isset($_GET['pg']) && !empty($_GET['pg'])?$_GET['pg']:1;
  23.   $posisi = ($pg-1)* $batas;
  24.   $tampil=mysql_query(
  25.   "
  26.     SELECT 0 as nip,COUNT(*) as nama,null,null,null
  27.     FROM pegawai
  28.  UNION
  29.     SELECT a.nip,a.nama,a.tgl_masuk,b.n_bag,c.n_jab
  30.     FROM pegawai a
  31.         JOIN bagian b USING(id_bag)
  32.         JOIN jabatan c USING(id_jab)
  33.     ORDER BY nip ASC
  34.     LIMIT $posisi, $batas
  35.  ");
  36.   $no=$posisi;
  37.   $d=mysql_fetch_assoc($tampil);
  38.   while($dt=mysql_fetch_assoc($tampil)){
  39.   echo "
  40.   <tr>
  41.    <td><center>".(++$no)."</center></td>
  42.    <td><center>{$dt['nip']}</center></td>
  43.    <td>{$dt['nama']}</td>
  44.     <td><center>{$dt['tgl_masuk']}</center></td>
  45.    <td><center>{$dt['n_bag']}</center></td>
  46.     <td><center>{$dt['n_jab']}</center></td>
  47.     <td><center><span><a href='?module=pegawai&act=edit&id={$dt['nip']}'>Edit</a></span>
  48.     <span>
  49.         <a href=\"$aksi?module=pegawai&act=hapus&id={$dt['nip']}\"
  50.             onClick=\"return confirm('Apakah Anda benar-benar mau menghapusnya?')\">Hapus</a></span>
  51.     <span><a href='?module=pegawai&act=detail&id={$dt['nip']}'>Detail</a></span></center></td>
  52.  </tr>";
  53.   }
  54. echo "  
  55. </table>
  56.     ";
  57.     $jml_data = $d['nama'];
  58.     //Jumlah halaman
  59.     $JmlHalaman = ceil($jml_data/$batas); //ceil digunakan untuk pembulatan keatas
  60.     //Navigasi ke sebelumnya
  61.     $prev = ( $pg > 1 )?"<a href='?pg=".($pg-1)."'>Sebelumnya </a>":"Sebelumnya ";
  62.     //Navigasi nomor
  63.     $nmr = '';
  64.     for ( $i = 1; $i<= $JmlHalaman; $i++ ){
  65.         $nmr .= ( $i == $pg )?$i . " ":"<a href='?pg=$i'>$i</a> ";
  66.     }
  67.     //Navigasi ke selanjutnya
  68.     $next = ( $pg < $JmlHalaman )?" <a href='?pg=".($pg + 1)."'>Selanjutnya</a>":" Selanjutnya";
  69.     //Tampilkan navigasi
  70.     echo $prev . $nmr . $next;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement