Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Need Help Reloading Previously Selected Checkboxes

$
0
0

Hello fellow PHP developers.  I have been stuck on a problem I just can not figure out.  I am developing a couple forms (insert and update) that users fill out.  On this form is general user information (first and last name fields, etc.) as well as a checkbox group based on an available “groups” table.  When the user fills out the form and makes their checkbox selections I write the user information to a user table, and write the user’s checkbox choices to a user_group_xref  table (unique_id, fk_user_id, fk_group_id) for as many choices as the user selected.  The fk_user_id is a foreign key to the user table, and the fk_group_id is a foreign key to the group table.

User_table

Unique_id, first_name, last_name, address

Groups_table

Unique_id, group_description, active_flag

User_group_xref table

Unique_id, fk_user_id, fk_group_id

 

This all works correctly for the insert, and I can make the selections out of the tables no problem.  To get the users previous selections, I query the xref table and join it back to the group table for the description. My user_groups query returns g.unique_id, g.group_description for the appropriate user. I generate the checkboxes with the following code:

<?php

do { ; ?>

                <br />

                <label>

                                <input type="checkbox" name="admin_groups[]" value="<?php echo $row_groups['pkID']; ?>" id="admin_groups_<?php echo $row_groups['pkID']; ?>"

                                tabindex="<?php echo $iTabIndexCounter;?>" />

                                <?php echo $row_groups['group_description']; ?>

                </label>

<?php } while ($row_groups = mysql_fetch_assoc($groups)); ?>

 

This works fine in generating the checkboxes.  How do I at the same time check those checkboxes previously selected?  The only thing I can think of is to show only those checkboxes actually selected, but I want all checkboxes displayed, and those previously selected checked.  Any suggestions would be greatly appreciated. 

 

 

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles