Postingan lainnya
Filter data Bedasarkan ruang?
hai semua disini saya akan melakukan filter data sesuai ruangan/, berikut struktur tabel yang saya miliki.
tabel ruang/lokasi "kd_lokasi, lokasi, deskripsi";
tabel barang "id_barang, nama_barang, kd_jenisb(fk), masa_ekonomis, jml_barang, satuanbarang, kd_lokasi(fk), stay_pinjaman, deskrpsbarang"
berikut form filternya
<form action="" method="POST">
<div class="form-group">
<label class="">Pilih Ruang</label>
<label for="" class="col-md-4">
<select name="kd_lokasi" class="form-control" required>
<option value="" hidden>Pilih Ruang</option>
<?php
$lokasi = $conn->query("SELECT * FROM tb_lokasi");
while ($as = $lokasi->fetch_array()) : ?>
<option value="<?= $as['kd_lokasi']; ?>">
<?= $as['lokasi']; ?>
</option>
<?php endwhile; ?>
</select>
</label>
<label for="" class="col-md-4">
<button type="submit" name="filter" value="Filter" class="btn btn-success">Filter</button>
</label>
</div>
</form>
Berikut query yang akan di jalankan
<tbody>
<?php if (isset($_POST['filter'])) {
$query = $conn->query("SELECT * FROM tb_barang AS a
LEFT JOIN tb_lokasi AS b ON a.kd_lokasi=b.kd_lokasi LEFT JOIN tb_jenisbarang AS c ON a.kd_jenisb=c.kd_jenisb WHERE kd_lokasi = '" . $_POST['kd_lokasi'] . "'");
} else {
$query = $conn->query("SELECT * FROM tb_barang AS a
LEFT JOIN tb_lokasi AS b ON a.kd_lokasi=b.kd_lokasi LEFT JOIN tb_jenisbarang AS c ON a.kd_jenisb=c.kd_jenisb");
}
// print_r($query);
foreach ($query as $data) {
?>
<tr>
<td><?= $no++; ?></td>
<td><?= $data['nama_barang']; ?></td>
<td><?= $data['jenisbarang']; ?></td>
<td><?= $data['masa_ekonomis']; ?></td>
<td><?= $data['jml_barang']; ?></td>
<td><?= $data['lokasi']; ?></td>
<td><?= $data['stay_pinjaman']; ?></td>
<td>
<a href="?page=editguru&id=<?= $data['id_barang']; ?>" class="btn btn-warning btn-sm"><i class="fas fa-pencil-alt"></i></a>
<form action="?page=delguru&id=<?= $data['id_barang']; ?>" method="post" class="d-inline" id="del-<?= $data['id_barang']; ?>">
<input type="hidden" name="_method" value="DELETE">
<button class="btn btn-danger btn-sm" data-confirm="Data Akan Di Hapus! | Apakah Anda Yakin?" data-confirm-yes="submitDel(<?= $data['id_barang']; ?>)"><i class="fas fa-trash"></i>
</button>
</form>
</td>
</tr>
<?php } ?>
</tbody>
dari script di atas saat tombol filter dijalankan terdapat kesalahan seperti berikut : Warning: foreach() argument must be of type array|object, bool given in D:\laragon\www\db_up\sma\page\barang\barang.php on line 86
0
Belum ada Jawaban. Jadi yang pertama Jawaban
Login untuk ikut Jawaban