A
Anonymous
Guest
I have a page that has 138 checkboxes on it. I have the page set so it can accept the input and also reshow the saved input.
The names of the checkboxes are r1 r2 r3 r4 ... r137 r138. I also have 138 columns in a mysql database named the same r1 r2 .. etc.
When the form is submitted I get the checkbox value like this. (Now I know this is not the best way to get a checkbox value but it works so I have been using it. I convert the checkbox value to either Y or N.)
Now rather than write this 138 times to set the variables to Y or N for each checkbox, and then input 138 values into the database at once it would be a lot easier to have a loop that sets the variable and inputs the value one at a time. My attempts so far at writing this loop have failed. Any hints or help would be greatly appreciated.
Code:
<?php if (($r1) == "Y") {
echo '<input type="checkbox" name="r1" value="ON" checked>';
} else {
echo '<input type="checkbox" name="r1" value="ON">'; } ?>
When the form is submitted I get the checkbox value like this. (Now I know this is not the best way to get a checkbox value but it works so I have been using it. I convert the checkbox value to either Y or N.)
Code:
if ($r1 == "ON") {
$r1 = "Y";
} else {
$r1 = "N";
}
Now rather than write this 138 times to set the variables to Y or N for each checkbox, and then input 138 values into the database at once it would be a lot easier to have a loop that sets the variable and inputs the value one at a time. My attempts so far at writing this loop have failed. Any hints or help would be greatly appreciated.