<div class="form-group">
<label>Fasilitas: </label>
<div class="row skin skin-flat">
<div class="col-md-4 col-sm-12">
<?php
$gfasis = (explode(", ",$i['gedung_fasilitas']));
$fasi = [
1=>
"Catering",
"Dekorasi Pelaminan",
"Photo & Video Akad Resepsi",
"Album Kolase",
"Makeup",
"Mc / Pembawa Acara",
"Weeding Organizer",
"Entertainment",
"Pakaian Pengantin",
"Ruang Full AC",
"Meja VIP",
"Lighting",
"Lcd Proyektor",
"Tari Tradisional",
"Photo Both",
"Seragam Keluarga",
"Seragam Orang tua",
"Meja Akad nikah",
"Buku Tamu",
"Kotak Amplop",
"Box Hantaran",
"Free Menginap di Hotel",
"Qoori Akad / Resepsi",
"Ruang Hias",
"Raung Tunggu Pengantin",
"Beskap Pengantin",
"Rental Mobil Pengantin",
"Kursi sofa",
"Meja makan prasmanan",
"Gazebo Pintu Masuk",
"Red Carpet"
];
for($kk=1; $kk<=11; $kk++) {
?>
<fieldset>
<input type="checkbox" id="<?= $kk; ?>" name="fasilitas[]" value="<?= $kk; ?>">
<label for="<?= $kk; ?>"><?= $fasi[$kk]; ?></label>
</fieldset>
<?php } ?>
</div>
<div class="col-md-4 col-sm-12">
<?php
for($kk=12; $kk<=21; $kk++) {
?>
<fieldset>
<input type="checkbox" id="<?= $kk; ?>" name="fasilitas[]" value="<?= $kk; ?>">
<label for="<?= $kk; ?>"><?= $fasi[$kk]; ?></label>
</fieldset>
<?php } ?>
</div>
<div class="col-md-4 col-sm-12">
<?php
for($kk=22; $kk<=31; $kk++) { ?>
<fieldset>
<input type="checkbox" id="<?= $kk; ?>" name="fasilitas[]" value="<?= $kk; ?>">
<label for="<?= $kk; ?>"><?= $fasi[$kk]; ?></label>
</fieldset>
<?php } ?>
</div>
</div>
</div>
您可以看到我的复选框仍为0,因此必须选中此复选框
当我添加此代码时
for($kk=1; $kk<=11; $kk++) { ?>
<fieldset>
<input type="checkbox" id="<?= $kk; ?>" name="fasilitas[]" value="<?= $kk; ?>" <?php if($gfasis[$kk]==$kk){echo "checked";} else {}?>>
<label for="<?= $kk; ?>"><?= $fasi[$kk]; ?></label>
</fieldset>
<?php } ?>
我遇到这样的错误
也许有人可以帮助我吗? 我只需要检查与我的数据库相同的值
答案 0 :(得分:1)
简单答案 替换此行
<?php if($gfasis[$kk]==$kk){echo "checked";} else {}?>
使用此代码
<?php if (in_array($kk, $gfasis)){ echo "checked";}?>
所以您的代码将是这样
for($kk=1; $kk<=11; $kk++) { ?>
<fieldset>
<input type="checkbox" id="<?= $kk; ?>" name="fasilitas[]" value="<?= $kk; ?>"
<?php if (in_array($kk, $gfasis)) {echo "checked";} else {}?>>
<label for="<?= $kk; ?>"><?= $fasi[$kk]; ?></label>
</fieldset>
<?php } ?>