On my site, I have multiple checkbox fields, where each input doubles in value from the previous, like this:
<form name=test>
<input type='checkbox' name='groupe' value = '1'>
<input type='checkbox' name='groupe' value = '2'>
<input type='checkbox' name='groupe' value = '4'>
<input type='checkbox' name='groupe' value = '8'>
<input type='checkbox' name='groupe' value = '16'>
etc...
</form>
I stock the fields selected (by the user) result in summing all of the values selected.
Let's say that the user had selected 4 and 1. In this case, I insert the sum of field values, which is 5. At this stage, after insert, my SQL table is:
test
5
I need to retrieve the values selected to create this result number 5.
The information to do that are: - 31 (the max result, which is the sum of each field 1+2+4+8+16) - it is impossible to get a result value of 5 using 2+2+1, because an input cannot be selected twice;
I did a lot of searching to solve this, but I couldn't find anything helpful. How do I do this in SQL or PHP?