Kaskus

Tech

fauzigalihAvatar border
TS
fauzigalih
Ada yg tau cara mengaitkan checkbox pada id yg ada di database?
Assalamu'alaikum
Numpang nnya gan, ane ada problem untuk mengaitkan id pd checkbox.
ane lagi bikin halaman absensi, Ada yg tau cara mengaitkan checkbox pada id yg ada di database? berikut skript absensi.php

<form action="proses_absensi.php" method="post">
<table id="datatable-responsive" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Hadir</th>
<th>Sakit</th>
<th>Izin</th>
<th>Alpha</th>
</tr>
</thead>
<tbody>
<?php
$query=mysql_query("SELECT * FROM user order by nama ASC");
$t=0;
$no=1;
while($data=mysql_fetch_array($query)){
?>
<tr>
<td>
<?php echo $no; ?>
<input type="hidden" name="id" value="<?php echo $data['id'];?>"/>
</td>
<td>
<?php echo $data['nama']; ?>
</td>
<td>

<?php echo "<input type=checkbox name=hadir[] value=$data[id]>";?>
</td>
<td>
<?php
echo "<input type=checkbox name=hadir[] value=$data[id]>";

?>
</td>
<td>
<?php
echo "<input type=checkbox name=hadir[] value=$data[id]>";

?>
</td>
<td>
<?php
echo "<input type=checkbox name=hadir[] value=$data[id]>";

?>
</td>
</tr>
<?php
$no++;
}
?>
</tbody>
</table>
<button type="submit" name="submit" class="btn btn-success"><i class="fa fa-save m-right-xs"></i> Simpan</button>
</form>



untuk skript proses_absensi.php dpt dari panduan yg lain. berikut :
<?php
include "koneksi.php";
$id=$_POST['id'];
if(isset($_POST['submit'])){

if(!empty($_POST['hadir'])){
//parameter
$hadir=mysql_query("UPDATE user SET hadir='3' where id='$id'");

}

if(!empty($_POST['sakit'])){
//parameter
$kd_siswa=$_POST['sakit'];
$jumlah=count($kd_siswa);


for($i=0;$i<$jumlah;$i++){
$hadir=mysql_query("insert into absensi(kd_siswa,kd_kelas,keterangan,tanggal,selesai) values('$kd_siswa[$i]','$kd_kelas','s','$tanggal','yes')",$koneksi);
}

?>
[removed]document.location.href="?page=view_absensi&kd_kelas=<?php echo $kd_kelas;?>&tanggal=<?php echo $tanggal;?>";[removed]
<?php
}

if(!empty($_POST['ijin'])){
//parameter
$kd_siswa=$_POST['ijin'];
$jumlah=count($kd_siswa);


for($i=0;$i<$jumlah;$i++){
$hadir=mysql_query("insert into absensi(kd_siswa,kd_kelas,keterangan,tanggal,selesai) values('$kd_siswa[$i]','$kd_kelas','i','$tanggal','yes')",$koneksi);
}

?>
[removed]document.location.href="?page=view_absensi&kd_kelas=<?php echo $kd_kelas;?>&tanggal=<?php echo $tanggal;?>";[removed]
<?php
}

if(!empty($_POST['alfa'])){
//parameter
$kd_siswa=$_POST['alfa'];
$jumlah=count($kd_siswa);


for($i=0;$i<$jumlah;$i++){
$hadir=mysql_query("insert into absensi(kd_siswa,kd_kelas,keterangan,tanggal,selesai) values('$kd_siswa[$i]','$kd_kelas','a','$tanggal','yes')",$koneksi);
}

?>
[removed]document.location.href="?page=view_absensi&kd_kelas=<?php echo $kd_kelas;?>&tanggal=<?php echo $tanggal;?>";[removed]
<?php
}
}else{
unset($_POST['selesai']);
?>[removed]document.location.href="?page=input_absensi&kd_kelas=<?php echo $kd_kelas;?>&tanggal=<?php echo $tanggal;?>";[removed]<?php
}
?>


pd bagian skript proses_absensi.php, yang baru diubah cuma bagian hadir nya saja. utk memastikan data berhasil terupdate atau tidak.
dan ternyata berhasil terupdate. tp masalahnya , Hanya 1 Record Saja yg Terupdate
emoticon-Ngakak

Mohon Bantuannyaemoticon-Shakehand2
0
2.6K
9
GuestAvatar border
Komentar yang asik ya
Mari bergabung, dapatkan informasi dan teman baru!
Website, Webmaster, Webdeveloper
Website, Webmaster, Webdeveloper
KASKUS Official
23.5KThread5.4KAnggota
Urutkan
Terlama
GuestAvatar border
Komentar yang asik ya
Ikuti KASKUS di
© 2026 KASKUS, PT Darta Media Indonesia. All rights reserved.