How to explode array and assign chunks to respective checkbox fields?

appollauntove

New Member
Following situation: I stored a checkbox array with implode in a mysql table field. Now, in order to update the checkboxes, I want to read the table field content, explode it into its parts and assign it to the respective checkboxes.So far I managed to read out and explode the table field content into different chunks, my difficulty is how to assign to the respective checkboxes.Here is the checkbox field:\[code\]<tr> <td><input class="field checkbox" type="checkbox" name="appbox[]" value="http://stackoverflow.com/questions/3649099/Automotive" <?php $appbox_checked ?> /><label class="choice">Automotive</label></td> <td><input class="field checkbox" type="checkbox" name="appbox[]" value="http://stackoverflow.com/questions/3649099/Backlights" <?php $appbox_checked ?> /><label class="choice">Backlights</label></td> <td><input class="field checkbox" type="checkbox" name="appbox[]" value="http://stackoverflow.com/questions/3649099/LED lighting" <?php $appbox_checked ?> /><label class="choice">LED lighting</label></td> </tr> <tr> <td><input class="field checkbox" type="checkbox" name="appbox[]" value="http://stackoverflow.com/questions/3649099/IR" <?php $appbox_checked ?> /><label class="choice">IR</label></td> <td><input class="field checkbox" type="checkbox" name="appbox[]" value="http://stackoverflow.com/questions/3649099/Signage/Traffic Lights" <?php $appbox_checked ?> /><label class="choice">Signage/Traffic lights</label></td> <td><input class="field checkbox" type="checkbox" name="appbox[]" value="http://stackoverflow.com/questions/3649099/Mobile Devices" <?php $appbox_checked ?> /><label class="choice">Mobile devices</label></td> </tr>\[/code\]and here is the php code:\[code\]$storebox = explode(", ", $chunk0); for($i = 0; $i < count($storebox); $i++){ echo "Piece $i = $storebox[$i] <br />"; }\[/code\]The chunk content matches the value field of the checkbox. So what I need is basically:if 'chunk content' = 'checkbox value'then \[code\]<?php $appbox_checked ?>\[/code\] will echo 'checked'Or maybe there is a simplier solution. Thanks for you help guys!
 
Back
Top