2
In my database I have a table called cadastroatendo
within this table I put the days of attendance. I am recovering the data through the foreach... which in turn the array
returns this result:
[listaAtendo] => Array
(
[0] => stdClass Object
(
[codCadastroAtendo] => 46
[codCadastroPerfil] => 50
[codCadastroAtendoCat] => 7
)
[1] => stdClass Object
(
[codCadastroAtendo] => 47
[codCadastroPerfil] => 50
[codCadastroAtendoCat] => 8
)
[2] => stdClass Object
(
[codCadastroAtendo] => 48
[codCadastroPerfil] => 50
[codCadastroAtendoCat] => 9
)
)
I display the fields to be as "checked" case the codCadastroAtendoCat
is equal to the id shown in the listing. I list this way:
Model:
$sql_atendo = "SELECT * FROM cadastroatendo WHERE codCadastroPerfil = {$id}";
$valor->listaAtendo = $this->db->query($sql_atendo)->result();
View:
<div class="line" style="height: 70px;">
<table style="width: 100%;">
<?
$contagem = 0;
foreach($this->data['parametroAtendo'] as $valor){
if($contagem==0){
?>
<tr>
<? } $contagem++; ?>
<td style="300px;">
<input type="checkbox" name="atendo_codCadastroAtendoCat[]" value="<? echo $valor->idParametro; ?>" id="1_<? echo $valor->idParametro; ?>"> <label for="1_<? echo $valor->idParametro; ?>" style="text-align: left;"><? echo $valor->parametro; ?></label>
</td>
<? if($contagem==4){ $contagem = 0; ?>
</tr>
<? } } ?>
</table>
</div>
I need: when I am registered in the database table that ID, with that Profile, the field is as "checked". Someone can help me?
Explanation:
I have checkbox fields, which are previously registered in the database. I list all of them on the screen, and I write the selected ones in the table... I do the recovery, which comes through an array(), however, I cannot check if there is this record in the database, to put it as checked, when editing.