Jump to content

Best method/type to store 256 elements?


split63

Recommended Posts

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  :shrug:

Link to comment
Share on other sites

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')";
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.