Postingan lainnya
Menampilkan Data Dari Database
Gan ini kok tampil datanya ada 3 padahal di databse cuman 1
<?php
require_once 'core/init.php';
require_once 'template/header.php';
if (!isset($_SESSION['username'])) header('Location: login.php');
$id = isset($_GET['id']) ? $_GET['id'] : null;
if (isset($_GET['id']) ) {
$id_siswa = id_siswa($id);
while($row = mysqli_fetch_assoc($id_siswa)) {
$nis = $row['nis'];
$nama = $row['nama'];
$kelas = $row['kelas'];
$program = $row['program'];
}
}
?>
<div class="row">
<div class="col-sm-12">
<h2>Data Siswa</h2>
<div class="media">
<img class="mr-3" src="template/assets/admin.png" alt="Generic placeholder image">
<div class="media-body mb-4">
<h4><label for="nis">NIS: <?=$nis;?></label></h4>
<h4><label for="nama">Nama: <?=$nama;?></label></h4>
<h4><label for="kelas">Kelas: <?=$kelas;?></label></h4>
<h4><label for="program">Program: <?=$program;?></label></h4>
</div>
</div>
</div>
<div class="col-md-12 mt-4">
<h2>Riwayat Siswa</h2>
</div>
<div class="col-md-12">
<div class="table-responsive-sm">
<table class="table table-hover">
<tr class="bg-dark text-light">
<td class="text-center" width="50px">NO</td>
<td class="text-center" width="200px">TANGGAL</td>
<td class="text-center" width="150px">KATEGORI</td>
<td class="text-center" width="250px">TINDAKAN</td>
<td class="text-center" width="400px">KETERANGAN</td>
<td width="200px"></td>
</tr>
<?php if (isset($_GET['id']) ) {
$id_history= id_history($id);
$no = 0;
while($row = mysqli_fetch_assoc($id_history) ) :
$no++; ?>
<tr>
<td class="text-center"><?=$no;?></td>
<td class="text-center"><?=$row['tanggal'];?></td>
<td class="text-center"><?=$row['kategori'];?></td>
<td class="text-center"><?=$row['tindakan'];?></td>
<td class="text-center"><?=$row['keterangan'];?></td>
<td>
<a class="btn btn-primary" href="edit.php?id=<?= $row['id'];?>"><span data-feather="edit"></span> Edit</a>
<a class="btn btn-danger" href="delete.php?id=<?= $row['id'];?>"><span data-feather="delete"></span> Delete</a>
</td>
</tr>
<?php endwhile; } ?>
<?=print_r($id_history);?>
</table>
</div>
</div>
<div class="col-md-12">
<a class="btn btn-primary" id="button" href="add_history.php?id=<?=$_GET['id_siswa'];?>"><span data-feather="edit"></span> Tambah Data</a>
<a class="btn btn-danger" href="students.php?kelas=<?=$_GET['kelas'];?>">Kembali</a>
</div>
</div>
<?php require_once 'template/footer.php'; ?>
Ini functionnya
function id_history($id) {
global $conn;
$query = "SELECT tbl_siswa.id, tbl_riwayat.tanggal, tbl_riwayat.kategori, tbl_riwayat.tindakan, tbl_riwayat.keterangan
FROM tbl_siswa LEFT JOIN tbl_riwayat ON $id = tbl_riwayat.id_siswa";
$result = mysqli_query($conn, $query);
return $result;
}
0
3 Jawaban:
Sepertinya kesalahan pada kode bukan pada pemanggilan query database. Dan masalahnya tidak ada kode yg disertakan. Jadi gelap gulita :D
0