split63 Posted June 3, 2010 Share Posted June 3, 2010 I have an html form on which a user selects numbers from 0x00 to 0xFF. Each of the 256 numbers has a check box. They can select as many numbers that apply to them. The results will be stored in a mysql database. What type of mysql field should this be stored in? Ideally, only a true or false is needed for each number. I could store each number selected, or I could store a true/false for each of the 256 possibilities. This is an example of a smaller, brute-force HTML form to collect the numbers: <form action="checkbox-form.php" method="post"> Select your numbers<br /> <table> <tr> <td><input type="checkbox" name="numbers[]" value="0" />0 </td> <td><input type="checkbox" name="numbers[]" value="1" />1 </td> <td><input type="checkbox" name="numbers[]" value="2" />2 </td> <td><input type="checkbox" name="numbers[]" value="4" />4 </td> </tr> <tr> <td><input type="checkbox" name="numbers[]" value="10" />A</td> <td><input type="checkbox" name="numbers[]" value="11" />B</td> <td><input type="checkbox" name="numbers[]" value="12" />C</td> <td><input type="checkbox" name="numbers[]" value="13" />D</td> </tr> </table> <input type="submit" name="formSubmit" value="Submit" /> </form> The question is, how should this numbers[] array be stored in the database? Note that when pulling from the database, a message will be displayed for each of the 256 entries. For example the output would be Number: 0 - Selected 1 - Not Selected 2 - Selected . . 254 - Not Selected 255 - Not Selected Thanks Quote Link to comment https://forums.phpfreaks.com/topic/203806-best-methodtype-to-store-256-elements/ Share on other sites More sharing options...
ignace Posted June 4, 2010 Share Posted June 4, 2010 colors (id, user_id, red, green, blue) If you use my script I provided you earlier, you can insert them like: $user = $_SESSION['id']; foreach ($_POST['red'] as $key => $value) { $red = $value; $green = $_POST['green'][$key]; $blue = $_POST['blue'][$key]; $query = "INSERT INTO colors (user_id, red, green, blue) VALUES ('$user', '$red', '$green', '$blue')"; } Quote Link to comment https://forums.phpfreaks.com/topic/203806-best-methodtype-to-store-256-elements/#findComment-1067557 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.