Postingan lainnya
Bagaimana cara mengupdate data dari multiple checkbox?
Kan, saya mau meng-update dari gambar yang dipilih.. misal yang di gambarnya burem itu status=upload, yang gak burem status=Belum, terus kalau aku centang banyak ya berubah gitu aja dari status yg mulanya Belum jd Upload dan sebaliknya..
Tampil gambar :
<form class="form-horizontal" id="akun" name="example_form" action="?modul=home&aksi=update" method="POST" data-validate="parsley" enctype="multipart/form-data">
<?php
$b = mysql_query($tampil="SELECT a.*,b.nama FROM foto a, akun b WHERE a.pemilikfoto = b.id_akun ORDER BY a.tanggal_foto ASC") or die($tampil.'<br>error</br>'.mysql_error());
//$no=1;
while($rb = mysql_fetch_array($b)){
if($rb['status_foto'] == 'Belum'){
echo "
<div class='col-md-3'>
<input type='checkbox' name='idfoto' value='$rb[id_foto]' />
<img src='$rb[url]' class='img-thumbnail' alt='Cinque Terre' width='304' height='236'>
</div>";
}else{
echo "<div class='col-md-3'>
<input type='checkbox' name='idfoto' value='$rb[id_foto]' />
<img src='$rb[url]' class='img-thumbnail' alt='Cinque Terre' width='304' height='236' style='opacity: 0.3;background: black;'>
</div>
";
}
}
echo "
</div>
</div>
<br>
<center> <button type='submit' class='btn btn-primary btn-md' style='margin-left: 37px;'>UPDATE</button> </center>
</form>";
UPDATE GAMBAR :
$idfoto = $_POST['idfoto'];
$b = mysql_query($tampil="SELECT a.*,b.nama FROM foto a, akun b WHERE a.pemilikfoto = b.id_akun and a.id_foto='$idfoto' ORDER BY a.tanggal_foto ASC") or die($tampil.'<br>error</br>'.mysql_error());
//$no=1;
$rb = mysql_fetch_array($b);
if($rb['status_foto'] == 'Belum'){
$sqlupdate = "update foto set status_foto='Upload' where id_foto='$idfoto'";
$res=mysql_query ($sqlupdate) or die (mysql_error());
echo "<script>window.location = 'http://localhost/sacoret/admin/admin.php?modul=home'</script>";
}else{
$sqlupdate = "update foto set status_foto='Belum' where id_foto='$idfoto'";
$res=mysql_query ($sqlupdate) or die (mysql_error());
echo "<script>window.location = 'http://localhost/sacoret/admin/admin.php?modul=home'</script>";
}
Ini udah bisa update sih.. tapi gak bisa multiple
0
1 Jawaban:
Kalo mau multiple, coba ubah name dari checkboxnya jadi array, contoh:
<input type="checkbox" name="idfoto[]" value="...">
Dan bedain value-nya, jangan sama. Disarankan valuenya pake ID masing-masing item aja.
Terus tinggal get arraynya (karena udah jadi array bentuk inputnya). Dan terakhir tinggal loop lalu update.
CMIIW, semoga solved.
2