Postingan lainnya
Cetak data sesuai tanggal yang telah di filter | Cetak Data Berdasarkan Filter
Assalamualikum...
disini saya ingin mencetak data berdasarkan data yang di filter sebelumnya....
Berikut Tombol Filter
<form action="" method="post" class="form-inline">
<div class="row mt-4">
<input type="date" name="tglmulai" class="form-control">
<input type="date" name="tglselesai" class="form-control ml-3">
<button type="submit" name="filertgl" class="btn btn-sm btn-primary ml-3">Filter Data</button>
</div>
<div class="row">
</div>
</form>
Qurey filter data....
<?php
if (isset($_POST['filertgl'])) {
$tglmulai = $_POST['tglmulai'];
$tglselesai = $_POST['tglselesai'];
// jika tombol filter di tekan, tanpa input tanggal
if ($tglmulai != null || $tglselesai != null) {
$query = $conn->query("SELECT* FROM tb_pinjaman
INNER JOIN tb_sarpases ON tb_pinjaman.id = tb_sarpases.id
INNER JOIN tb_member ON tb_pinjaman.id_member = tb_member.id_member WHERE tglpinjam BETWEEN '$tglmulai' AND DATE_ADD('$tglselesai',INTERVAL 1 DAY) ORDER BY tglpinjam DESC");
} else {
$query = $conn->query("SELECT* FROM tb_pinjaman
INNER JOIN tb_sarpases ON tb_pinjaman.id = tb_sarpases.id
INNER JOIN tb_member ON tb_pinjaman.id_member = tb_member.id_member ORDER BY tglpinjam DESC");
}
} else {
$query = $conn->query("SELECT* FROM tb_pinjaman INNER JOIN tb_sarpases ON tb_pinjaman.id = tb_sarpases.id INNER JOIN tb_member ON tb_pinjaman.id_member = tb_member.id_member ORDER BY tglpinjam DESC");
$_SESSION['query'] = $query;
}
?>
script cetak data deng mpdf
<?php
require_once __DIR__ . '/../../../vendor/autoload.php';
require_once '../../../../inc/db.php';
if (isset($_POST['filertgl'])) {
$tglmulai = $_POST['tglmulai'];
$tglselesai = $_POST['tglselesai'];
// jika tombol filter di tekan, tanpa input tanggal
if ($tglmulai != null || $tglselesai != null) {
$query = $conn->query("SELECT* FROM tb_pinjaman
INNER JOIN tb_sarpases ON tb_pinjaman.id = tb_sarpases.id
INNER JOIN tb_member ON tb_pinjaman.id_member = tb_member.id_member WHERE tglpinjam BETWEEN '$tglmulai' AND DATE_ADD('$tglselesai',INTERVAL 1 DAY) ORDER BY tglpinjam DESC");
} else {
$query = $conn->query("SELECT* FROM tb_pinjaman
INNER JOIN tb_sarpases ON tb_pinjaman.id = tb_sarpases.id
INNER JOIN tb_member ON tb_pinjaman.id_member = tb_member.id_member ORDER BY tglpinjam DESC");
}
} else {
$query = $conn->query("SELECT* FROM tb_pinjaman INNER JOIN tb_sarpases ON tb_pinjaman.id = tb_sarpases.id INNER JOIN tb_member ON tb_pinjaman.id_member = tb_member.id_member ORDER BY tglpinjam DESC");
}
// $no = 1;
$html = '
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cetak Data Pinjaman</title>
<style>
h2{
// text-transform: uppercase;
color: #444;
font-size: 1.2em;
text-align: center;
// font-family: calibri;
}
p{
// text-align: center;
color: #444;
font-family: calibri;
}
.tabel1 {
font-family: sans-serif;
display: table;
color: #444;
border-collapse: collapse;
width: 95%;
margin: 10px auto;
}
.table1, th, td {
padding: 8px 20px;
// text-align: center;
}
</style>
</head>
<body>
<h2>DATA PEMINJAMAN BARANG
<br>SMA IBRAHIMY SUKOREJO
</h2>
<table class="tabel1" border="1">
<thead>
<tr bgcolor="#12e6bb">
<th colspan="6">PEMINJAMAN</th>
<th colspan="2">PENGEMBALIAN</th>
<!-- <th rowspan="2">Status</th> -->
</tr>
<tr>
<th>No</th>
<th width="200">Tanggal</th>
<th width="200">Nama</th>
<th width="40">Jumlah</th>
<th width="200">Nama Barang</th>
<th width="150">Alamat</th>
<th width="200">Tanggal</th>
<th width="150">Keterangan</th>
</tr>
</thead>
<tbody>';
$no = 1;
foreach ($query as $data) {
$html .= '<tr>
<td>' . $no++ . '</td>
<td>' . $data['tglpinjam'] . '</td>
<td>' . $data['nama_member'] . '</td>
<td>' . $data['jmlpinjam'] . '</td>
<td>' . $data['nama_sarpras'] . '</td>
<td>' . $data['alamat'] . '</td>
<td>' . $data['tglkembali'] . '</td>
<td>' . $data['keterangan'] . '</td>
</tr>';
}
$html .= '</tbody>
</table>
</body>
</html>';
$mpdf = new \Mpdf\Mpdf(['orientation' => 'L']);
$mpdf->WriteHTML($html);
$mpdf->Output('Data Pinjaman.pdf', 'I');
1 Jawaban:
<div>Kalau aku liat secara langsung ga ada masalah sih selain mubazir , menggunakan kodingan yang sama.<br><br>Memangnya hasil nya seperti apa yang jadi kendala?</div>
Tanggapan
kebdala nya data yang tercetak bukan data yang sudah di filter akan tetapi semua data yang ada di database
Itu ketika ditekan tombol nya kan? Bila menurut ku kendala nya bukan yang di atas. Tapi struktur tabel nya.
tipe data kolom tglpinjam nya apa udah 'Date" atau selainnya
tipe data pada kolom tglpinjam 'datetime', kalok filter datanya sudah jalan, sekarang tinggal cetak datanya berdasarkan filter tersebut