96 lines
2.5 KiB
PHP
96 lines
2.5 KiB
PHP
<?php
|
|
// panggil berkas koneksi.php
|
|
require 'koneksi.php';
|
|
|
|
// buat koneksi ke database mysql
|
|
koneksi_buka();
|
|
|
|
?>
|
|
|
|
<table class="table table-condensed table-bordered table-hover" cellpadding="0" cellspacing="0">
|
|
<thead>
|
|
<tr>
|
|
<th style="width:20px">#</th>
|
|
<th style="width:120px">NIM</th>
|
|
<th style="width:200px">Nama</th>
|
|
<th>Alamat</th>
|
|
<th style="width:120px">Kelas</th>
|
|
<th style="width:120px">Status</th>
|
|
<th style="width:40px"></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php
|
|
$i = 1;
|
|
$jml_per_halaman = 10; // jumlah data yg ditampilkan perhalaman
|
|
$jml_data = mysql_num_rows(mysql_query("SELECT * FROM mahasiswa"));
|
|
$jml_halaman = ceil($jml_data / $jml_per_halaman);
|
|
// query pada saat mode pencarian
|
|
if(isset($_POST['cari'])) {
|
|
$kunci = $_POST['cari'];
|
|
echo "<strong>Hasil pencarian untuk kata kunci $kunci</strong>";
|
|
$query = mysql_query("
|
|
SELECT * FROM mahasiswa
|
|
WHERE nim LIKE '%$kunci%'
|
|
OR nama LIKE '%$kunci%'
|
|
OR alamat LIKE '%$kunci%'
|
|
OR kelas LIKE '%$kunci%'
|
|
OR status LIKE '%$kunci%'
|
|
");
|
|
// query jika nomor halaman sudah ditentukan
|
|
} elseif(isset($_POST['halaman'])) {
|
|
$halaman = $_POST['halaman'];
|
|
$i = ($halaman - 1) * $jml_per_halaman + 1;
|
|
$query = mysql_query("SELECT * FROM mahasiswa LIMIT ".(($halaman - 1) * $jml_per_halaman).", $jml_per_halaman");
|
|
// query ketika tidak ada parameter halaman maupun pencarian
|
|
} else {
|
|
$query = mysql_query("SELECT * FROM mahasiswa LIMIT 0, $jml_per_halaman");
|
|
}
|
|
|
|
// tampilkan data mahasiswa selama masih ada
|
|
while($data = mysql_fetch_array($query)) {
|
|
if($data['status']==1) {
|
|
$status = "Aktif";
|
|
} else {
|
|
$status = "Tidak Aktif";
|
|
}
|
|
?>
|
|
<tr>
|
|
<td><?php echo $i ?></td>
|
|
<td><?php echo $data['nim'] ?></td>
|
|
<td><?php echo $data['nama'] ?></td>
|
|
<td><?php echo $data['alamat'] ?></td>
|
|
<td><?php echo $data['kelas'] ?></td>
|
|
<td><?php echo $status ?></td>
|
|
<td>
|
|
<a href="#dialog-mahasiswa" id="<?php echo $data['kd_mhs'] ?>" class="ubah" data-toggle="modal">
|
|
<i class="icon-pencil"></i>
|
|
</a>
|
|
<a href="#" id="<?php echo $data['kd_mhs'] ?>" class="hapus">
|
|
<i class="icon-trash"></i>
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<?php
|
|
$i++;
|
|
}
|
|
?>
|
|
</tbody>
|
|
</table>
|
|
|
|
<?php if(!isset($_POST['cari'])) { ?>
|
|
<!-- untuk menampilkan menu halaman -->
|
|
<div class="pagination pagination-right">
|
|
<ul>
|
|
<?php for($i = 1; $i <= $jml_halaman; $i++) { ?>
|
|
<li class="halaman" id="<?php echo $i ?>"><a href="#"><?php echo $i ?></a></li>
|
|
<?php } ?>
|
|
</ul>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<?php
|
|
// tutup koneksi ke database mysql
|
|
koneksi_tutup();
|
|
?>
|