Sie sind auf Seite 1von 11

<?

php

//koneksi dan error

ini_set("display_errors","off");

include "../../_Config/Connection.php";

//Atur Batas

$batas="10";

//Atur Page

if(!empty($_POST['page'])){

$page=$_POST['page'];

$posisi = ( $page - 1 ) * $batas;

}else{

$page="1";

$posisi = 0;

//Atur Keyword

if(isset($_POST['keyword'])){

$keyword=$_POST['keyword'];

}else{

$keyword="";

//hitung jumlah data

if(empty($keyword)){

$jml_data = mysqli_num_rows(mysqli_query($conn, "SELECT*FROM member"));

}else{

$jml_data = mysqli_num_rows(mysqli_query($conn, "SELECT*FROM member WHERE nama like '%


$keyword%' OR nik like '%$keyword%'"));
}

//Jumlah halaman

$JmlHalaman = ceil($jml_data/$batas);

$JmlHalaman_real = ceil($jml_data/$batas);

$prev=$page-1;

$next=$page+1;

if($next>$JmlHalaman){

$next=$page;

}else{

$next=$page+1;

if($prev<"1"){

$prev="1";

}else{

$prev=$page-1;

?>

<script>

$(document).ready(function(){

$('#ReloadMember').click(function(){

var Loading='<div class="row text-center"><div class="form-group col col-md-12"><img


src="images/loading.gif"></div></div>';

$('#TabelMember').html(Loading);

$('#TabelMember').load('_Page/Member/TabelMember.php');

});

//ketika Modal Delete muncul


$('#ModalDeleteMember').on('show.bs.modal', function (e) {

var Loading='<div class="row text-center"><div class="form-group col col-md-12"><img


src="images/loading.gif"></div></div>';

$('#FormDeleteMember').html(Loading);

var IdMember = $(e.relatedTarget).data('id');

$.ajax({

url : "_Page/Member/FormDeleteMember.php",

method : "POST",

data : { IdMember: IdMember },

success: function (data) {

$('#FormDeleteMember').html(data);

//Ketika disetujui delete

$('#ProsesDeleteMember').submit(function(){

var Loading='<div class="row text-center"><div class="form-group col col-md-12"><img


src="images/loading.gif"></div></div>';

$('#NotifikasiDeleteMember').html(Loading);

var ProsesDeleteMember = $('#ProsesDeleteMember').serialize();

$.ajax({

type : 'POST',

url : '_Page/Member/ProsesDeleteMember.php',

data : ProsesDeleteMember,

success : function(data){

$('#NotifikasiDeleteMember').html(data);

//menangkap keterangan notifikasi

var Notifikasi=$('#NotifikasiDeleteMemberBerhasil').html();

if(Notifikasi=="Berhasil"){
$('#Halaman').load('_Page/Member/Member.php');

$('#ModalDeleteMember').modal('hide');

$('#ModalDeleteMemberBerhasil').modal('show');

});

});

})

});

<?php

$a=1;

$b=$jml_data;

for ( $i =$a; $i<=$b; $i++ ){

?>

$('#EditMember<?php echo "$i";?>').click(function() {

var EditMember = $('#EditMember<?php echo $i;?>').val();

var mode = EditMember.split(',');

var IdMember = mode[0];

var page = mode[1];

var BatasData = mode[2];

$.ajax({

url : "_Page/Member/EditMember.php",

method : "POST",

data : { page: page, IdMember: IdMember, BatasData: BatasData, },


success: function (data) {

$('#Halaman').html(data);

})

});

<?php } ?>

//ketika klik next

$('#NextPage').click(function() {

var valueNext = $('#NextPage').val();

var mode = valueNext.split(',');

var page = mode[0];

var BatasData = mode[1];

$.ajax({

url : "_Page/Member/TabelMember.php",

method : "POST",

data : { page: page, BatasData: BatasData },

success: function (data) {

$('#TabelMember').html(data);

})

});

//Ketika klik Previous

$('#PrevPage').click(function() {
var ValuePrev = $('#PrevPage').val();

var mode = ValuePrev.split(',');

var page = mode[0];

var BatasData = mode[1];

$.ajax({

url : "_Page/Member/TabelMember.php",

method : "POST",

data : { page: page, BatasData: BatasData },

success : function (data) {

$('#TabelMember').html(data);

})

});

<?php

$a=1;

$b=$JmlHalaman;

for ( $i =$a; $i<=$b; $i++ ){

?>

//ketika klik page number

$('#PageNumber<?php echo $i;?>').click(function() {

var PageNumber = $('#PageNumber<?php echo $i;?>').val();

var mode = PageNumber.split(',');

var page = mode[0];

var BatasData = mode[1];

$.ajax({
url : "_Page/Member/TabelMember.php",

method : "POST",

data : { page: page, BatasData: BatasData },

success: function (data) {

$('#TabelMember').html(data);

})

});

<?php } ?>

});

</script>

<div class="card-body">

<div class="table-responsive">

<table class="table table-bordered">

<thead>

<tr>

<th>No</th>

<th>ID Member</th>

<th>Nama</th>

<th>Point</th>

<th>Option</th>

</tr>

</thead>

<tbody>

<?php
$no = 1+$posisi;

//KONDISI PENGATURAN MASING FILTER

if(empty($keyword)){

$query = mysqli_query($conn, "SELECT*FROM member ORDER BY nama DESC LIMIT


$posisi, $batas");

}else{

$query = mysqli_query($conn, "SELECT*FROM member WHERE nama like '%$keyword%'


OR nik like '%$keyword%' ORDER BY nama DESC LIMIT $posisi, $batas");

while ($data = mysqli_fetch_array($query)) {

$id_member = $data['id_member'];

$nama= $data['nama'];

$nik = $data['nik'];

$point = $data['point'];

?>

<tr>

<td><?php echo "$no";?></td>

<td><?php echo "$nik";?></td>

<td><?php echo "$nama";?></td>

<td><?php echo "$point";?></td>

<td align="center" width="10%">

<div class="btn-group">

<button class="btn btn-sm btn-info" id="EditMember<?php echo "$no";?>" <?php echo


"value='".$id_member.",".$page.",".$batas."'"; ?>>

<i class="menu-icon mdi mdi-pencil" aria-hidden="true"></i> Edit

</button>
<button class="btn btn-sm btn-danger" data-toggle="modal" data-
target="#ModalDeleteMember" data-id="<?php echo $id_member;?>">

<i class="menu-icon mdi mdi-delete" aria-hidden="true"></i> Hapus

</button>

</div>

</td>

</tr>

<?php $no++;} ?>

</tbody>

</table>

</div>

</div>

<div class="card-body">

<div class="row">

<div class="col col-lg-12">

<form action="javascript:void(0);" id="Paging">

<div class="btn-group" role="group" aria-label="Basic example">

<button type="button" class="btn btn-outline-secondary" id="PrevPage" <?php echo


"value='".$prev.",".$batas."'"; ?>>

<<

</button>

<?php

//Navigasi nomor

$nmr = '';

if($JmlHalaman>5){

if($page>=3){
$a=$page-2;

$b=$page+2;

if($JmlHalaman<=$b){

$a=$page-2;

$b=$JmlHalaman;

}else{

$a=1;

$b=$page+2;

if($JmlHalaman<=$b){

$a=1;

$b=$JmlHalaman;

}else{

$a=1;

$b=$JmlHalaman;

for ( $i =$a; $i<=$b; $i++ ){

?>

<button type="button" class="<?php if($i==$page){echo "btn btn-primary";}else{echo "btn


btn-grey";} ?>" id="PageNumber<?php echo $i;?>" <?php echo "value='".$i.",".$batas."'"; ?>>

<?php echo $i;?>

</button>

<?php

}
?>

<button type="button" class="btn btn-outline-secondary" id="NextPage" <?php echo


"value='".$next.",".$batas."'"; ?>>

>>

</button>

</div>

</form>

</div>

</div>

</div>