I have a dynamic check box element in my page that is generated from items in a mysql database table. I wish it to compair this list to a secondary table, which contains a list of items that have been selected in a previous session, and check mark those items. This way the user can see what settings she had previously and modify them to her needs.
I'm not sure how I can set this up, but I do know there will be an if then statment to compair the first table to the second to determin if there is a match. However since the list is generated dynamically, I'm not sure what I need to know to loop both lists at the same time.
Any ideas?
Thanks
Auto Checking a Check box from a Database selection
Moderator: General Moderators
-
microthick
- Forum Regular
- Posts: 543
- Joined: Wed Sep 24, 2003 2:15 pm
- Location: Vancouver, BC
Code: Select all
$count = count($arrayOfCheckboxes);
for ($i = 0; $i < $count; $i++) {
if (in_array($arrayOfCheckboxesї$i], $arrayOfSelectedCheckboxes)) {
// output check box selected
} else {
// output check box
}
}Basically, it loops through all the checkboxes, and sees if that checkboxes value is in the selected array.