In my database I have a table called cadastroatendo
within this table I put the days of service. I'm retrieving the data through foreach ... which in turn 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 "checked" if codCadastroAtendoCat
is equal to the id displayed in the listing. Done 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 to: When the database is registered in the database table, with that Profile, the field is marked as "checked". Can anyone help me?
Explanation:
I have checkbox fields, which are previously registered in the database. I can not see if there is a record in the database, to put it as checked, at the time to edit.