I have an application where I collect some of the form input with checkboxes. All input is saved to a database. I can get the checkbox data out of the database and i can get it to display so that checked data appears checked, and the rest of the checkboxes that weren't previously checked just appear unchecked. I was only able to get all of that working with help/answers from a terrific phpbuilder.com member - devinemke. (See http://www.phpbuilder.com/board/showthread.php?threadid=10266181)
Below, I've placed the database structure and devinemke's code that displays checked/unchecked boxes in my form. Now what I want to do is display the checked/unchecked checkboxes in columns. I'm having a wicked time getting this to work. I have about 30 (and growing) checkboxes that can appear. I've tried a few things in a bunch of ways but get all kinds of whacky displays. Like each checkbox appears 30 times, or 30 tables holding all of the checkboxes, and on.
Does anyone know how to rework the code below so that my 30 checkboxes appear in, say, 3 columns of 10 checkboxes each? Any help is extremely appreciated! Thanks!
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
pet_data_id | person_id | pet_id
1 | 1 | 1
2 | 1 | 3
3 | 2 | 1
4 | 2 | 2
5 | 2 | 4
$result = mysql_query ('SELECT * FROM pets');
while ($row = mysql_fetch_array ($result)) {
$pets[$row['pet_id']] = $row['type_of_pet'];
}
$result = mysql_query ("SELECT * FROM pet_data WHERE person_id = '$person_id'");
while ($row = mysql_fetch_array ($result)) {
$pet_data[$row['pet_data_id']] = $row['pet_id'];
}
echo 'We currently have the following pets listed for your profile:<br><br>';
foreach ($pets as $key => $value) {
echo '<input type="checkbox" name="pet_data[]" value="' . $key . '"';
if (in_array ($key, $pet_data)) {
echo ' checked';
}
echo '>' . $value . '<br>';
}