Guest User

Untitled

a guest
Jun 24th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.33 KB | None | 0 0
  1. <?php
  2. /*
  3.      
  4.         Displays all data from 'senarai' table
  5.         This is a modified version of papar.php that includes pagination
  6. */
  7.  
  8.         // connect to the database
  9.         include('dbase.php');
  10.        
  11.         // number of results to show per page
  12.         $per_page = 5;
  13.        
  14.         // figure out the total pages in the database
  15.         $result = mysql_query("SELECT * FROM permintaan");
  16.         $total_results = mysql_num_rows($result);
  17.         $total_pages = ceil($total_results / $per_page);
  18.  
  19.         // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
  20.         if (isset($_GET['page']) && is_numeric($_GET['page']))
  21.         {
  22.                 $show_page = $_GET['page'];
  23.                
  24.                 // make sure the $show_page value is valid
  25.                 if ($show_page > 0 && $show_page <= $total_pages)
  26.                 {
  27.                         $start = ($show_page -1) * $per_page;
  28.                         $end = $start + $per_page;
  29.                 }
  30.                 else
  31.                 {
  32.                         // error - show first set of results
  33.                         $start = 0;
  34.                         $end = $per_page;
  35.                 }              
  36.         }
  37.         else
  38.         {
  39.                 // if page isn't set, show first set of results
  40.                 $start = 0;
  41.                 $end = $per_page;
  42.         }
  43.        
  44.         // display pagination
  45.        
  46.         echo "<p><a href='papar.php'>Keseluruhan</a> | <b>Muka Surat:</b> ";
  47.         for ($i = 1; $i <= $total_pages; $i++)
  48.         {
  49.                 echo "<a href='mukasurat.php?page=$i'>$i</a> ";
  50.         }
  51.         echo "</p>";
  52.                
  53.         // display data in table
  54.         echo "<table border='6' cellpadding='20'>";
  55.         echo "<tr> <th>ID</th> <th>Nama</th> <th>No_telefon</th> <th>Alamat</th> <th>Catatan</th> <th>Tarikh</th> <th>Masa</th> <th>Jenis Peralatan</th><th></th> <th></th> </tr>";
  56.  
  57.         // loop through results of database query, displaying them in the table
  58.         for ($i = $start; $i < $end; $i++)
  59.         {
  60.                 // make sure that PHP doesn't try to show results that don't exist
  61.                 if ($i == $total_results) { break; }
  62.        
  63.                 // echo out the contents of each row into a table
  64.                 echo "<tr>";
  65.                 echo '<td>' . mysql_result($result, $i, 'id') . '</td>';
  66.                 echo '<td>' . mysql_result($result, $i, 'nama') . '</td>';
  67.                 echo '<td>' . mysql_result($result, $i, 'no_telefon') . '</td>';
  68.         echo '<td>' . mysql_result($result, $i, 'alamat') . '</td>';
  69.         echo '<td>' . mysql_result($result, $i, 'komen') . '</td>';
  70.         echo '<td>' . mysql_result($result, $i, 'tarikh') . '</td>';
  71.         echo '<td>' . mysql_result($result, $i, 'masa') . '</td>';
  72.         echo '<td>' . mysql_result($result, $i, 'ppertama') . '</td>'; ///kat sini ak nk add lagi  3 data iaitu pkedua,pketiga,pkeempat
  73.         echo '<td><a href="brgmohon_ctk.php?id=' . mysql_result($result, $i, 'id') . '">Cetak</a></td>';
  74.                 echo '<td><a href="ubah.php?id=' . mysql_result($result, $i, 'id') . '">Ubah</a></td>';
  75.                 echo '<td><a href="buang.php?id=' . mysql_result($result, $i, 'id') . '">Hapus</a></td>';
  76.                 echo "</tr>";
  77.         }
  78.         // close table>
  79.         echo "</table>";
Add Comment
Please, Sign In to add comment