How to retrieved data separated by comma and store it in checkbox as checked. I'm using explode so that the string data converted into an array. My problem is I can't get the logic behind this code. For example the data are "Parents, Grandparents, Friends" and I want to checked the checkbox depends upon that data. Thank you in advance. Here's my code not working:
<?php
$db_living_whom = explode(",", $fetch['living_whom']);
?>
<label>Living with whom</span></label>
<div class="row">
<?php
foreach ($db_living_whom as $value) {
?>
<div class="col-md-2">
<label class="checkbox-inline">Parents
<input type="checkbox" <?php if($value == "Parent") echo "checked"; ?> disabled>
</label>
</div>
<div class="col-md-3">
<label class="checkbox-inline">Brothers & Sisters
<input type="checkbox" <?php if($value == "Brothers & Sister") echo "checked"; ?> disabled>
</label>
</div>
<div class="col-md-2">
<label class="checkbox-inline">Grandparents
<input type="checkbox" <?php if($value == "Grandparents") echo "checked"; ?> disabled>
</label>
</div>
<div class="col-md-2">
<label class="checkbox-inline">Other Relatives
<input type="checkbox" <?php if($value == "Other Relatives") echo "checked"; ?> disabled>
</label>
</div>
<div class="col-md-2">
<label class="checkbox-inline">Friends
<input type="checkbox" <?php if($value == "Friends") echo "checked"; ?> disabled>
</label>
</div>
<?php } ?>
</div>
In that code the checkboxes load 4 times (because of foreach loop) and the "Parents, Grandparents, Friends" are not checked.
Aucun commentaire:
Enregistrer un commentaire