Best Methods for Storing Checkbox Information in a MySQL Database
| From: | Kath | Date: | Thu, 06 Sep 2001 20:27:04 +0000 |
| Subject: | Best Methods for Storing Checkbox Information in a MySQL Database | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-66272@lists.php.net to get a copy of this message | ||
I have some checkboxes on a form.
Now I figured out how to store them in a database sandwiched together (like
thing1,thing2,thing3,thing4).
However, what is the best method for storing them each in an individual
field.
This is what I'd really like:
| userid | otherthing |
| 1 | azu |
| 1 | cde |
| 1 | foo |
| 2 | bar |
Would it be something like:
Count the number of things, then do
for($x = 0, $x <= $numberofthings; $x++) {
$sql = "INSERT INTO table (userid, otherthing) VALUES ('$userid',
'$things[$x]')";
$result = mysql_query($sql);
if (!$result) { blaherrorchecking(); }
}
What do you all think of that? Is it a good solution? Lousy? A hack job?
Is there a better way?
- k