0
According to the code below, I need to make sure that when loading the page, a table is loaded with checkbox marked, according to database data, for example:
Destino
_______________________________________
Origem | 1 | 2 | 3 | 4 | 5 |
--------|-------|-------|-------|-------|-------|
1 | | X | | | |
--------|-------|-------|-------|-------|-------|
2 | | | X | | |
--------|-------|-------|-------|-------|-------|
3 | | | | X | |
--------|-------|-------|-------|-------|-------|
4 | | | | | X |
--------|-------|-------|-------|-------|-------|
5 | | | | | |
Where the X
would be according to the database, forming the following array
:
$transicao => array( (int) 0 => array( 'origem' => 1, 'destino' => 2 ) (int) 1 => array( 'origem' => 2, 'destino' => 3 ) (int) 2 => array( 'origem' => 3, 'destino' => 4 ) (int) 3 => array( 'origem' => 4, 'destino' => 5 )
Current code:
Copying and pasting the code on this website, you will see the same in operation
<?php
$status = array(
[
'origem' => 1,
],
[
'origem' => 2,
],
[
'origem' => 3,
],
[
'origem' => 4,
]
);
//simulando dados do banco de dados
$transicao = array(
[
'origem' => 1,
'destino' => 2
],
[
'origem' => 2,
'destino' => 3
],
[
'origem' => 3,
'destino' => 4
],
[
'origem' => 4,
'destino' => 5
]
);
echo "
<table cellpadding='0' cellspacing='0'>
<tr> <!-- Aqui é montado a primeira linha da tabela que é a do cabeçalho -->
<th> ORIGEM </th>";
foreach ($status as $xkey => $xvalue) :
echo "<th bgcolor='#cccc0'> " . $xvalue['origem'] . "</th>";
endforeach;
echo "</tr><tr>";
// foreach que percorre as colunas
foreach ($status as $ykey => $yvalue) :
echo "<td bgcolor='#ddddd'> " . $yvalue['origem'] . "</td>";
foreach ($status as $xkey => $xvalue) :
$value = $yvalue['origem'] . '|' . $xvalue['origem'];
echo "<td>
<input type='checkbox' name='origem" . $value . "destino value='" . $value . "'>
</td>";
endforeach;
echo "</tr>";
endforeach;
echo "</table>";
When giving "echo" in the input, make a check to see if that should be checked, if that’s the case put the checked attribute="checked".
– José Eduardo Kimura
Because it is José, I did it, but I have not yet found the correct logic to mark only those that exist in the database, when I do this check, he marks some and then there are other checkboxes if you have any marked, I am trying here, anything I put the result, if you have another alternative I will be grateful for the help xD
– Marcos Henzel