php-crud-oop/index.php

105 lines
3.1 KiB
PHP
Raw Normal View History

2020-01-02 23:24:47 +07:00
<?php
include('database.php');
include('mahasiswa.php');
$mhs = new Mahasiswa();
$mhs->connect();
if (isset($_GET['id'])){
$mhs->deletemhs($_GET['id']);
}
$page = null;
$search = null;
//cek apakah ada getPage
if (isset($_GET['page']))$page = $_GET['page'];
//cek apakah ada getSearch
if ((isset($_GET['search'])) && (($_GET['search'])!='')){
$search = $_GET['search'];
$mhs->select('mahasiswa','*',"nama LIKE '%$search%' or nim LIKE '%$search%'");
}
else{
$mhs->select('mahasiswa');
}
$res = $mhs->getResult();
//pagination
if (!array_key_exists(0, $res)){
$resu[0]=$res;
$result = $mhs->paging($resu,5,$page,$search);
}
else{
$result = $mhs->paging($res,5,$page,$search);
}
?>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link href="style.css" rel="stylesheet">
<link href="bootstrap.min.css" rel="stylesheet">
<script>
function delconfirm(id){
var del=confirm('Are you sure you want to delete '+id+' record?');
if (del==true) window.location.href = 'index.php?id='+id;
else window.location.href = 'index.php';
}
</script>
</head>
<body>
<div class="container" style="margin-top:50px;">
<div class="page-header">
<h1>Data Mahasiswa</h1>
</div>
<div class="row">
<div class="navbar span11">
<div class="navbar-inner">
<form class="navbar-search pull-left" method="get" action="index.php">
<div class="input-append">
<input type="text" class="span2" name="search" placeholder="Search..." value="<?php if (isset($_GET['search'])) echo $_GET['search']; ?>">
<a href="index.php"><button type="button" class="btn btn-small"><i class="icon-remove"></i></button></a>
</div>
</form>
<a href="form.php"><button class="btn btn-small btn-primary pull-right" style="margin-top:8px;">+ Tambah</button></a>
</div>
</div>
</div>
<div class="row"><div class="span11">
<table class="table table-striped table-bordered">
<thead>
<th style="width:100px">NIM</th>
<th style="width:100px">Nama</th>
<th style="width:200px">Alamat</th>
<th style="width:130px">Telp</th>
<th style="width:200px">Sekolah Asal</th>
<th style="width:50px">Action</th>
</thead>
<tbody>
<?php
$i=$result['mulai'];
if( !empty( $result['data'] ) ){
foreach ($result['data'] as $value) {
?>
<tr>
<td><?php echo $result['data'][$i]['nim'] ?></td>
<td><?php echo $result['data'][$i]['nama'] ?></td>
<td><?php echo $result['data'][$i]['alamat'] ?></td>
<td><?php echo $result['data'][$i]['telp'] ?></td>
<td><?php echo $result['data'][$i]['asal'] ?></td>
<td>
<a href="<?php echo 'view.php?id='.$result['data'][$i]['nim'] ?>"><i class="icon-eye-open" title="View"></i></a>
<a href="<?php echo 'form.php?id='.$result['data'][$i]['nim'] ?>"><i class="icon-edit" title="Edit"></i></a>
<i class="icon-trash" title="Delete" onclick="delconfirm(<?php echo $result['data'][$i]['nim'] ?>)"></i>
</td>
</tr>
<?php
$i++;
}
}
?>
</tbody>
</table>
</div></div>
<?php
echo $result['paging'];
$mhs->disconnect();
?>
</div>
</body>
</html>