What potential issues could arise when using checkboxes in PHP to display results from a database and how can they be resolved?

Issue: One potential issue when using checkboxes in PHP to display results from a database is that the checkboxes may not retain their checked status when the form is submitted. This can be resolved by checking if the checkbox value matches the database value and setting the 'checked' attribute accordingly.

<?php
// Assuming $results is an array of database results
foreach ($results as $result) {
    $checked = ($result['status'] == 1) ? 'checked' : '';
    echo '<input type="checkbox" name="checkbox[]" value="' . $result['id'] . '" ' . $checked . '>';
}
?>