I am currently from a form, obtaining the days from Monday to Sunday as follows:
<td><dl class="dropdown">
<dt>
<a href="#">
<span class="hida">Dias</span>
<p class="multiSel"></p>
</a>
</dt>
<dd>
<div class="mutliSelect">
<ul>
<li>
<input type="checkbox" name="dias[]" value="64" />Lunes</li>
<li>
<input type="checkbox" name="dias[]" value="32" />Martes</li>
<li>
<input type="checkbox" name="dias[]" value="16" />Miercoles</li>
<li>
<input type="checkbox" name="dias[]" value="8" />Jueves</li>
<li>
<input type="checkbox" name="dias[]" value="4" />Viernes</li>
<li>
<input type="checkbox" name="dias[]" value="2" />Sabado</li>
<li>
<input type="checkbox" name="dias[]" value="1" />Domingo</li>
</ul>
</div>
</dd>
</dl></td>
The numbers are because to insert in my mysql table, I must insert a single value, and I do not want to insert, Monday, Tuesday, Wednesday, etc. So I'm inserting the total that I get this way in the POST
//Saber la suma de los dias
$dias = $_POST['dias'];
$suma = 0;
if(count($dias) > 0){
foreach($dias as $valor){
$suma_d += $valor;
}
}
The issue is that now I need to present through html what days I chose and I must convert the number to the days, the formula would be for example if I choose, Tuesday, Wednesday and Friday
32 + 16 + 4 = 52 52 fits in 64 = No - Then it's not Monday 52 fits in 32 = Yes - Then it's Tuesday and I'm still 52 - 32 * 1 = 20 20 fits in 16 = Yes- Then it's Wednesday and I'm still 20 - 16 * 1 = 4 4 fits in 8 = No then it's not Thursday 4 fits in 4) Yes - Then it's Friday and I'm still 0 I can not continue. The days are Tuesday, Wednesday and Friday.
This is how I should do it but I do not know how to present it in PHP.