- Pembuatan halaman untuk menampilkan data dari database
- listMahasiswa.php
1: <?php
2: include("phpclass/CMahasiswa.php");
3: $cm = new CMahasiswa();
4: $query = $cm->getList();
5: #pagging
6: $jumlah = mysql_num_rows($query);
7: $limit= 5;
8: if(isset($_GET['page'])){
9: $hal = $_GET['page'];
10: }else{
11: $hal = 1;
12: }
13: $mulai = ($hal - 1)* $limit;
14: $pagging = $cm->getPage($mulai,$limit);
15: # select * from mahasiswa limit {$mulai},{$limit}
16: $totalpage = ceil($jumlah/$limit);
17: ?>
18: <table width="75%" class="table">
19: <tr>
20: <td colspan="5">
21: <a href="index.php?m=formMahasiswa" class="btn btn-danger">Tambah Mahasiswa</a>
22: </td>
23: <td colspan="2">
24: <?php
25: if(!isset($_GET['page'])){
26: $pageof = 1;
27: }else{
28: $pageof = $_GET['page'];
29: }
30: echo "Halaman $pageof dari $totalpage";
31: ?>
32: </td>
33: </tr>
34: <tr>
35: <th>No</th>
36: <th>NIM</th>
37: <th>Nama Mahasiswa</th>
38: <th>Jenis Kelamin</th>
39: <th>Agama</th>
40: <th>Hapus</th>
41: <th>Edit</th>
42: </tr>
43: <?php
44: $no=$mulai + 1;
45: while($row = mysql_fetch_array($pagging)){
46: ?>
47: <tr>
48: <td><?=$no;?></td>
49: <td><?=$row['nim'];?></td>
50: <td><?=ucwords($row['nmmhs']);?></td>
51: <td><?=$row['jnskel'];?></td>
52: <td><?=$row['agama'];?></td>
53: <td><a href="hapusMahasiswa.php?nim=<?=$row['nim'];?>" onClick="return konfirmasi('<?=$row['nmmhs'];?>')">Hapus</a></td>
54: <td><a href="index.php?m=formUpdateMahasiswa&nim=<?=$row['nim'];?>" >Edit</a></td>
55: </tr>
56: <?php
57: $no++;
58: }
59: ?>
60: <tr>
61: <td colspan="7">
62: <ul class="pagination">
63: <?php
64: if($mulai > 1) echo "<li><a href='index.php?m=listMahasiswa&page=".($hal-1)."'>Prev</a></li>";
65: for ($a = 1; $a <= $totalpage;$a++){
66: echo "<li><a href='index.php?m=listMahasiswa&page=".$a."'>$a</a></li>";
67: }
68: if($hal < $totalpage) echo "<li><a href='index.php?m=listMahasiswa&page=".($hal+1)."'>Next</a></li> ";
69: ?>
70: </ul>
71: </td>
72: </tr>
73: </table>
74: <!-- pagging -->
75: <script language="javascript">
76: function konfirmasi(del){
77: tanya = confirm('PERHATIAN !!! \n Anda akan menghapus Mahasiswa dengan nama " '+ del + ' " \n Lanjutkan ?');
78: if (tanya == true)
79: return true;
80: else
81: return false;
82: };
83: </script>
Tampilannya akan menjadi sebagai berikut:
Daftar List Mahasiswa |
1: <?php
2: include("phpclass/CMatkul.php");
3: $mk = new CMatkul();
4: $query = $mk->getList();
5: #pagging
6: $jumlah = mysql_num_rows($query);
7: $limit= 5;
8: if(isset($_GET['page'])){
9: $hal = $_GET['page'];
10: }else{
11: $hal = 1;
12: }
13: $mulai = ($hal - 1)* $limit;
14: $pagging = $mk->getPage($mulai,$limit);
15: # select * from mahasiswa limit {$mulai},{$limit}
16: $totalpage = ceil($jumlah/$limit);
17: ?>
18: <table width="75%" class="table">
19: <tr>
20: <td colspan="5">
21: <a href="index.php?m=formMatakuliah" class="btn btn-danger">Tambah Matakuliah</a>
22: </td>
23: <td colspan="2">
24: <?php
25: if(!isset($_GET['page'])){
26: $pageof = 1;
27: }else{
28: $pageof = $_GET['page'];
29: }
30: echo "Halaman $pageof dari $totalpage";
31: ?>
32: </td>
33: </tr>
34: <tr>
35: <th>No</th>
36: <th>Kode Matkul</th>
37: <th>Matakuliah</th>
38: <th>SKS</th>
39: <th>Dosen</th>
40: <th>Hapus</th>
41: <th>Edit</th>
42: </tr>
43: <?php
44: $no = $mulai + 1;
45: while($row = mysql_fetch_array($pagging)){
46: ?>
47: <tr>
48: <td><?=$no;?></td>
49: <td><?=$row['kode'];?></td>
50: <td><?=ucwords($row['matakuliah']);?></td>
51: <td><?=$row['sks'];?></td>
52: <td><?=strtoupper($row['dosen']);?></td>
53: <td><a href="hapusMatakuliah.php?kode=<?=$row['kode'];?>" onClick="return konfirmasi('<?=$row['matakuliah'];?>')">Hapus</a></td>
54: <td><a href="index.php?m=formUpdateMatakuliah&kode=<?=$row['kode'];?>">Edit</a></td>
55: </tr>
56: <?php
57: $no++;
58: }
59: ?>
60: <tr>
61: <td colspan="7">
62: <ul class="pagination">
63: <?php
64: if($mulai > 1) echo "<li><a href='index.php?m=listMatakuliah&page=".($hal-1)."'>Prev</a></li>";
65: for ($a = 1; $a <= $totalpage;$a++){
66: echo "<li><a href='index.php?m=listMatakuliah&page=".$a."'>$a</a></li>";
67: }
68: if($hal < $totalpage) echo "<li><a href='index.php?m=listMatakuliah&page=".($hal+1)."'>Next</a></li> ";
69: ?>
70: </ul>
71: </td>
72: </tr>
73: </table>
74: <script language="javascript">
75: function konfirmasi(del){
76: tanya = confirm('PERHATIAN !!! \n Anda akan menghapus matakuliah dengan nama " '+ del + ' " \n Lanjutkan ?');
77: if (tanya == true)
78: return true;
79: else
80: return false;
81: };
82: </script>
Tampilannya akan menjadi sebagai berikut:
Daftar List Matakuliah |
1: <?php
2: include("phpclass/CAdmin.php");
3: $cm = new CAdmin();
4: $query = $cm->getList();
5: #pagging
6: $jumlah = mysql_num_rows($query);
7: $limit= 5;
8: if(isset($_GET['page'])){
9: $hal = $_GET['page'];
10: }else{
11: $hal = 1;
12: }
13: $mulai = ($hal - 1)* $limit;
14: $pagging = $cm->getPage($mulai,$limit);
15: # select * from mahasiswa limit {$mulai},{$limit}
16: $totalpage = ceil($jumlah/$limit);
17: ?>
18: <table width="75%" class="table">
19: <tr>
20: <td colspan="5" align="right">
21: <?php
22: if(!isset($_GET['page'])){
23: $pageof = 1;
24: }else{
25: $pageof = $_GET['page'];
26: }
27: echo "Halaman $pageof dari $totalpage";
28: ?>
29: </td>
30: </tr>
31: <tr>
32: <th>No</th>
33: <th>Nama</th>
34: <th>Username</th>
35: <th>Password</th>
36: <th>Masuk terakhir pada:</th>
37: </tr>
38: <?php
39: $no=$mulai + 1;
40: while($row = mysql_fetch_array($pagging)){
41: ?>
42: <tr>
43: <td><?=$no;?></td>
44: <td><?=ucwords($row['nama']);?></td>
45: <td><?=$row['user'];?></td>
46: <td><?=substr($row['pass'],0,20);?> ...</td>
47: <td><?=$row['log'];?></td>
48: </tr>
49: <?php
50: $no++;
51: }
52: ?>
53: <tr>
54: <td colspan="5">
55: <ul class="pagination">
56: <?php
57: if($mulai > 1) echo "<li><a href='index.php?m=listAdmin&page=".($hal-1)."'>Prev</a></li>";
58: for ($a = 1; $a <= $totalpage;$a++){
59: echo "<li><a href='index.php?m=listAdmin&page=".$a."'>$a</a></li>";
60: }
61: if($hal < $totalpage) echo "<li><a href='index.php?m=listAdmin&page=".($hal+1)."'>Next</a></li> ";
62: ?>
63: </ul>
64: </td>
65: </tr>
66: </table>
67: <!-- pagging -->
Tampilannya akan mejadi sebagai berikut:
Daftar List Admin |
- hapusMahasiswa.php
1: <?php
2: include ("phpclass/CMahasiswa.php");
3: $nimna = $_GET['nim'];
4: $cm = new CMahasiswa();
5: $hps = $cm->getDelete($nimna);
6: if($hps){
7: ?>
8: <script language="javascript">
9: alert("Berhasil Menghapus data");
10: document.location="index.php?m=listMahasiswa";
11: </script>
12: <?php
13: }else{
14: ?>
15: <script language="javascript">
16: alert("Gagal Menghapus data");
17: document.location="index.php?m=listMahasiswa";
18: </script>
19: <?php
20: }
21: ?>
1: <?php
2: include ("phpclass/CMatkul.php");
3: $id = $_GET['kode'];
4: $cm = new CMatkul();
5: $hps = $cm->getDelete($id);
6: if($hps){
7: ?>
8: <script language="javascript">
9: alert("Berhasil Menghapus data");
10: document.location="index.php?m=listMatakuliah";
11: </script>
12: <?php
13: }else{
14: ?>
15: <script language="javascript">
16: alert("Gagal Menghapus data");
17: document.location="index.php?m=listMatakuliah";
18: </script>
19: <?php
20: }
21: ?>
Okey, sampai disini dulu, kita akan bahas selanjutnya di bagian 6 yaitu Membuat Halaman Adminisnistrator dan CRUD Menggunakan Konsep Pemrograman Berbasis Object (OOP) Bagian 6/6
UPDATE:
Lihat demo programnya: demo
Download full code nya: download code
UPDATE:
Lihat demo programnya: demo
Download full code nya: download code
0 Response to " Membuat Halaman Adminisnistrator dan CRUD Menggunakan Konsep Pemrograman Berbasis Object (OOP) Bagian 5/6 "
Post a Comment