1. Buatlah DAtabase dengan Nama : smk
2. buatlah Table dengan nama siswa
3. Listing Program
config.php
<?php
$servername = "localhost";
$username = "root";
$password = ""; // jika tidak ada user dan password
$dbase = "smk"; //nama database kalian
// koneksi database
$conn = new mysqli($servername, $username, $password,$dbase);
// cek koneksi database
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
cari.php
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker({ dateFormat: 'yy-mm-dd' });
$( "#datepicker2" ).datepicker({ dateFormat: 'yy-mm-dd' });
} );
</script>
</head>
<body>
<?php
include "config.php";
$sql = mysqli_query($conn,"SELECT * FROM siswa");
$z="0";
if (isset($_POST['cari'])) {
$tgl1=$_POST['tgl1'];
$tgl2=$_POST['tgl2'];
$cari = mysqli_query($conn,"SELECT * FROM siswa WHERE tgl_lulus BETWEEN '$tgl1' AND '$tgl2'");
$z="1";
if (mysqli_num_rows($cari)<1) {
$cari = mysqli_query($conn,"SELECT * FROM siswa");
}
}
?>
<form action="" method="post">
<b>Laporan Tanggal Kelulusan Siswa per Periode </b><br />
<p>Dari Tanggal: <input type="text" id="datepicker" name="tgl1">
Sampai Tanggal: <input type="text" id="datepicker2" name="tgl2"> <input type="submit" value="cari" name="cari"></p>
</form>
<table border="1" width="400">
<tr>
<td>Nis</td>
<td>Nama</td>
<td>kota</td>
<td>Tgl Lulus</td>
</tr>
<?php
if ($z=="1") {
?>
<?php
while($row = mysqli_fetch_array($cari))
{
?>
<tr>
<td><?php echo $row["nis"]; ?></td>
<td><?php echo $row["nama"]; ?></td>
<td><?php echo $row["kota"]; ?></td>
<td><?php echo $row["tgl_lulus"]; ?></td>
</tr>
<?php
}
?>
<?php
}
else{
?>
<?php
while($row = mysqli_fetch_array($sql))
{
?>
<tr>
<td><?php echo $row["nis"]; ?></td>
<td><?php echo $row["nama"]; ?></td>
<td><?php echo $row["kota"]; ?></td>
<td><?php echo $row["tgl_lulus"]; ?></td>
</tr>
<?php
}
}
?>
</table>
</body>
</html>
4. Output
DIKUMPULKAN VIA EMAIL : harrysupandi@gmail.com
Tidak ada komentar:
Posting Komentar