As the code below, I need to make a table loaded with checked checkboxes, depending on the bank's data, for example:
Destino
_______________________________________
Origem | 1 | 2 | 3 | 4 | 5 |
--------|-------|-------|-------|-------|-------|
1 | | X | | | |
--------|-------|-------|-------|-------|-------|
2 | | | X | | |
--------|-------|-------|-------|-------|-------|
3 | | | | X | |
--------|-------|-------|-------|-------|-------|
4 | | | | | X |
--------|-------|-------|-------|-------|-------|
5 | | | | | |
Where X
would conform 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 site , 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>";