I want to repopulate a page that contains checkboxes from values in the database. Currently, they are being stored as a string that gets split into an array when processing e.g 3,4,5.
I am able to check the boxes with the data from my database but another empty checkbox is created by its side. How do I only check the boxes with data from the database without having a duplicate empty box by its side?
<tbody>
<?php
if(!empty($datatable)){
foreach ($datatable as $data){
?>
<tr>
<td>
<?php foreach ($event_contacts as $checked){?>
<?php if($checked==$data->id){?>
<input type="checkbox" name="id[]" id="id" checked value="<?php echo $data->id; ?>"/>
<?php }else{ ?>
<input type="checkbox" name="id[]" id="id" value="<?php echo $data->id; ?>"/>
<?php }}?>
</td>
<td><?php echo $data->first_name." ".$data->last_name; ?></td>
<td><?php echo $data->email; ?></td>
<td><?php echo $data->phone_number; ?></td>
<td><?php echo $data->address;?></td>
</tr>
<?php
}
}
?>
</tbody>
Hope someone can help. Thanks
EDIT: Added photo for clarity
Aucun commentaire:
Enregistrer un commentaire