I have an application where I collect some of the form input with checkboxes. Part of this application is an edit form where people will login and get to their personal information and be able to modify it.
What I want to do with the checkbox data in the edit form is echo all possible checkboxes back to the screen and automatically check the ones that were previously selected while still providing people with all possible checkboxes so that they can uncheck ones that were previously checked, or check ones that now apply.
I've looked at a ton of posts in PHPBuilder that deal with this type of thing, but none that I've seen deal with data the way I've set it up in my database. I'm pretty sure this is because I'm using an associative table to collect some of the data rather than using comma-delimited data that all goes into one cell. Giving you the database set-up will be quicker than trying to describe what's going on. I'm not dealing with pets, but this is essentially what I've got going on:
Personal Info Table
person_id | name | location
1 | Lee | Chicago
2 | Phil | New York
Pet Lookup Table
pet_id | type_of_pet
1 | dog
2 | cat
3 | turtle
4 | goldfish
5 | ferrett
Pet Data Table
data_id | person_id | their_pet
1 | 1 | dog
2 | 1 | turtle
3 | 2 | dog
4 | 2 | cat
5 | 2 | goldfish
Since one person might have many pets, I decided to break this data out into its own associative Pet Data table. Using the data above and putting Phil's profile together, Phil is from New York and he has a dog, a cat, and a goldfish. When Phil comes back to the site to update his profile because his goldfish died, he needs to see the following in the Pet Checkboxes part of the edit for and be able to uncheck goldfish as well as, say, check turtle:
We currently have the following pets listed for your profile:
[x] dog
[x] cat
[ ] turtle
[x] goldfish
[ ] ferrett
I can get the initial data into the database and display it without any problems. But when someone comes back to the application to edit their profile, I can't get my checkboxes -- those that are already selected being checked and those that aren't yet selected showing as unchecked-- to display in the edit form. I'm pretty sure this will take a foreach condition, but I just can't figure out how to set it up. Any help is greatly appreciated! Thanks!