2
I have 2 fields, as below, which are checkboxes
:
<tr>
<td>Dizeres Legais:</td>
<td><input type="checkbox" name="export_dizeres[]" value="PORTUGUES"> Português
<input type="checkbox" name="export_dizeres[]" value="INGLES"> Inglês
<input type="checkbox" name="export_dizeres[]" value="ESPANHOL"> Espanhol
<input type="checkbox" name="export_dizeres[]" value="FRANCES"> Francês
<input type="checkbox" name="export_dizeres[]" value="ARABE"> Árabe
<input type="checkbox" name="export_dizeres[]" value="COREANO"> Coreano</td>
</tr>
<tr>
<td>Tabela Nutricional:</td>
<td><input type="checkbox" name="export_tabela[]" value="PORTUGUES"> Português
<input type="checkbox" name="export_tabela[]" value="INGLES"> Inglês
<input type="checkbox" name="export_tabela[]" value="ESPANHOL"> Espanhol
<input type="checkbox" name="export_tabela[]" value="FRANCES"> Francês
<input type="checkbox" name="export_tabela[]" value="ARABE"> Árabe
<input type="checkbox" name="export_tabela[]" value="COREANO"> Coreano</td>
</tr>
Step them into PHP, I can display them as follows:
$listaDizeres = $_POST['export_dizeres'];
foreach ($listaDizeres as $export_dizeres) {
echo $export_dizeres.'<br>';
}
$listaTabela = $_POST['export_tabela'];
foreach ($listaTabela as $export_tabela) {
echo $export_tabela.'<br>';
}
My question is this: I need to create a field for each checkbox
in the database or can I save all results together in a single field, such as an array? In case you later create a change form using Ajax, I can correctly mark the checkboxes
searching the data in the database?
For example, N of these checkboxes are then associated with N users, so create an associative table that will have the user id and the checkbox id. Do not use fields that contain several values that give the first form standard (1FN), a column for each checkbox already imagined if the number increases a lot? already have idea of how to separate the values for the right columns?
– rray
You can use serialize($listingDizeres) and save to the data field, right? This won’t be useful if you require a future SELECT based on this.
– Inkeliz
In fact each check will be associated with a project, but the relation will be yes N to N. This idea of creating a table part seemed to me the best solution. There will always be these 12 fields (6 for each). @lnkeliz, how does this serialize work?
– Diego
The part table is best option (or a column for each item, which can also be an option, but not the best one). Serialize will exactly turn the entire array into a string, summarizing. It will allow you to send the entire array "as is" directly to the database, you can read in the future using unserialize ($mysql['column']). The problem this method is several, especially if you intend to use a "WHERE sayings = "Arabe" or "JOIN..." will be literally impossible, but it is precisely the option of "I can record all results together in a single field".
– Inkeliz