ARTICLE AD BOX
As you pointed out in your comment to the other answer, the problem is
A student can have the same badge/award, which shows as a checkbox, in two or more Requirements sections. I did not know this was possible. Found it on a random check. I uncheck one from one section, but it remains checked in another, which is why it still appears in the form_badges array. Hours on this. Sigh. I know what I have to do now.
Hence, if your badge is duplicated across multiple requirement sections, if you uncheck it in one requirement section, but not the others, then the badge will still exist and it will show as checked even where you unchecked it. Hence, you need to make a business decision: either you want the badge not to be required in the required section where you unchecked it, but to have it still checked in the sections where you did not uncheck it, or to have it unchecked everywhere if you unchecked it somewhere.
Since you did not define what your data model looks like and how your requirement sections look alike, I cannot be sure how it is exactly modeled, but you likely have a table for requirement_sections, a badges table and a badges_in_sections table.
So, if you want to uncheck all similar badges in all requirement sections if it was unchecked somewhere, then you need to do the equivalent of
delete from badges_in_sections where badge_id = %iwhere the badge_id would be the value you parameterize to your query. However, this is a less probable intent, since if you have a badge of moderator and this badge is required for the forum moderation requirement section as well as in the moderator vote requirement section and you decide to uncheck it for the latter, so non-moderators will have the privilege to vote too, then moderation should probably still require one to be a moderator. In this case your delete is likely the equivalent of
delete from badges_in_sections where badge_id = %i and section_id = %iso you remove the badge from the section in a parameterized manner. However, if this is the case, then you need to load $db_badge_ids with the equivalent of
select badge_id, section_id from badges_in_sectionsgroup the results as an array that will end up looking like
[ 1: [1, 2, 3], 2: [3, 4, 5] ]where the keys are the section ids and the values are the badge ids and therefore when you are to display the checkboxes, you need to loop your requirement sections and badges inside, something like
if( is_array($requirements) ){ //requirements of a section foreach( $requirements as $req ){ $checked = ''; if( in_array($req['id'], $db_badge_ids['section_id']) ){ //we check for the requirement in the section $checked = 'checked="checked"'; } ?> <input type="checkbox" name="form_badges[]" id="badge_<?= $req['id'] ?>" <?= $checked ?> value="<?= $req['id'] ?>" /> <label for="badge_<?= $req['id'] ?>"><?= $req['requirement_name'] ?></label> <br /> <?php ?> <?php } // end foreachSo you check for the requirement inside your current section and hence if there are similar badge requirements in multiple sections, you differentiate between the sections not just by the badge, but also the section itself.
