Advertisement
aisya_r

Script Paging

Nov 6th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang = "en">
  3. <head>
  4.     <title>Studi Kasus</title>
  5. </head>
  6. <body>
  7. <?php
  8.     $host='localhost';
  9.     $username='root';
  10.     $password='';
  11.     $database='myweb';
  12.     $conn = mysqli_connect($host, $username, $password, $database);
  13.     if (!$conn){
  14.         die("Connection Failed : ".mysqli_connect_error);
  15.     }
  16.     if(!isset($_GET['start'])) {
  17.         $start = 0;
  18.     } else {
  19.         $start = $_GET['start'];
  20.     }
  21.     $data = mysqli_query($conn,"SELECT * FROM mahasiswa LIMIT $start, 5;") or die("Gagal :".mysqli_error());
  22. ?>
  23.         <table align="center" border="1">
  24.             <tr>
  25.                 <th width = "100">NIM</th>
  26.                 <th width = "100">Nama</th>
  27.                 <th width = "100">Alamat</th>
  28.                 <th width = "100">Data</th>            
  29.             </tr>
  30. <?php
  31.             while ($rec=mysqli_fetch_row($data))  
  32.             {
  33. ?>             
  34.                 <tr>
  35.                     <td>
  36.                         <a href="manage.php?nama=<?php echo $rec[1] ?>&alamat=<?php echo $rec[2]?>">
  37.                             <?php echo $rec[0] ?>
  38.                         </a>
  39.                     </td>
  40. <?php
  41.                     echo '<td>'.$rec[1].'</td>';           
  42.                     echo '<td>'.$rec[2].'</td>';
  43. ?>
  44.                     <td>
  45.                         <button onclick = "var r = confirm('Hapus NIM <?php echo $rec[0]; ?>?'); if(r==true){ window.location.href='delete.php?nim=<?php echo $rec[0] ?>'; return r;} ">
  46.                             Hapus
  47.                         </button>
  48.                     </td>
  49.                 </tr>
  50. <?php
  51.             }
  52. ?>
  53.             </table>
  54. <?php          
  55.             $query = mysqli_query($conn, "SELECT * FROM mahasiswa");
  56.             $num = mysqli_num_rows($query);
  57.             if($num > 5) {
  58. ?>
  59.                 <a href = "index.php?start=0">Page 1</a>
  60.                 <a href = "index.php?start=5">Page 2</a>
  61. <?php
  62.                 $num = $num -5;
  63.             }
  64.             $startpage = 5;
  65.             $page = 3;
  66.             while($num > 5) {
  67.             $startpage = $startpage+5;
  68. ?>
  69.                 <a href = "index.php?start=<?php echo $startpage ?>">Page <?php echo $page ?></a>
  70. <?php
  71.             $page = $page + 1;
  72.             $num = $num - 5;
  73.             }
  74. ?>
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement