Skip to content

Instantly share code, notes, and snippets.

@hanafiah
Created October 18, 2016 05:21
Show Gist options
  • Save hanafiah/778c36e742c2a2969f2f8dd58825ad1b to your computer and use it in GitHub Desktop.
Save hanafiah/778c36e742c2a2969f2f8dd58825ad1b to your computer and use it in GitHub Desktop.
<input name="sample[]" type="checkbox" value="1"> Test 1
<input name="sample[]" type="checkbox" value="2"> Test 2
<input name="sample[]" type="checkbox" value="4"> Test 3
<input name="sample[]" type="checkbox" value="8"> Test 4
<input name="sample[]" type="checkbox" value="16"> Test 5
===========
1. DB relationship
tblsample
---------------
id | name
1 | Test 1
2 | Test 2
4 | Test 3
8 | Test 4
16 | Test 5
tblanswer
---------------
id | desc
1 | lorem ipsum
2 | dolor sit amet
tblselectionmatch
---------------
id | sample_id | answer_id
1 | 2 | 2
2 | 8 | 2
3 | 16 | 2
4 | 8 | 1
2. store as string (Comma deliminated / json / serialize etc )
Get array value and convert it to string
tblanswer
---------------
id | desc | selection
1 | lorem ipsum | 8
2 | dolor sit amet | 2, 8, 16
3. bitmask
Get array value and sum it
tblanswer
---------------
id | desc | selection
1 | lorem ipsum | 8
2 | dolor sit amet | 26
4. Any other options?..
@khairulfathi
Copy link

Don't see the need for tblselectionmatch. Can simply add tblsample.id in tblanswer, unless of course there's another layer of data granularity that you need to store but not shown here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment