Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Displays all data from 'senarai' table
- This is a modified version of papar.php that includes pagination
- */
- // connect to the database
- include('dbase.php');
- // number of results to show per page
- $per_page = 5;
- // figure out the total pages in the database
- $result = mysql_query("SELECT * FROM permintaan");
- $total_results = mysql_num_rows($result);
- $total_pages = ceil($total_results / $per_page);
- // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
- if (isset($_GET['page']) && is_numeric($_GET['page']))
- {
- $show_page = $_GET['page'];
- // make sure the $show_page value is valid
- if ($show_page > 0 && $show_page <= $total_pages)
- {
- $start = ($show_page -1) * $per_page;
- $end = $start + $per_page;
- }
- else
- {
- // error - show first set of results
- $start = 0;
- $end = $per_page;
- }
- }
- else
- {
- // if page isn't set, show first set of results
- $start = 0;
- $end = $per_page;
- }
- // display pagination
- echo "<p><a href='papar.php'>Keseluruhan</a> | <b>Muka Surat:</b> ";
- for ($i = 1; $i <= $total_pages; $i++)
- {
- echo "<a href='mukasurat.php?page=$i'>$i</a> ";
- }
- echo "</p>";
- // display data in table
- echo "<table border='6' cellpadding='20'>";
- 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>";
- // loop through results of database query, displaying them in the table
- for ($i = $start; $i < $end; $i++)
- {
- // make sure that PHP doesn't try to show results that don't exist
- if ($i == $total_results) { break; }
- // echo out the contents of each row into a table
- echo "<tr>";
- echo '<td>' . mysql_result($result, $i, 'id') . '</td>';
- echo '<td>' . mysql_result($result, $i, 'nama') . '</td>';
- echo '<td>' . mysql_result($result, $i, 'no_telefon') . '</td>';
- echo '<td>' . mysql_result($result, $i, 'alamat') . '</td>';
- echo '<td>' . mysql_result($result, $i, 'komen') . '</td>';
- echo '<td>' . mysql_result($result, $i, 'tarikh') . '</td>';
- echo '<td>' . mysql_result($result, $i, 'masa') . '</td>';
- echo '<td>' . mysql_result($result, $i, 'ppertama') . '</td>'; ///kat sini ak nk add lagi 3 data iaitu pkedua,pketiga,pkeempat
- echo '<td><a href="brgmohon_ctk.php?id=' . mysql_result($result, $i, 'id') . '">Cetak</a></td>';
- echo '<td><a href="ubah.php?id=' . mysql_result($result, $i, 'id') . '">Ubah</a></td>';
- echo '<td><a href="buang.php?id=' . mysql_result($result, $i, 'id') . '">Hapus</a></td>';
- echo "</tr>";
- }
- // close table>
- echo "</table>";
Add Comment
Please, Sign In to add comment