assign radio value found in sql - Codeigniter

1

I want the user to load the data update page to see the data that he has entered in his record. I can see the data that is in type = text but not in type = radius.

View:

<?php foreach ($resultados_pesquisa as $linha) {
   $nome = $linha["NOME"];
   $genero $linha["GENERO"];
   ?>

<form class="form-horizontal" action="<?php echo site_url('Menu');?>" method="post" accept-charset="utf-8">
          <h3>Dados pessoais</h3>

<!-- Nome -->
  <div class="form-group">
   <label for="inputName" class="col-sm-2 control-label">Nome</label>
    <input type="text" name="nome" value="<?php   echo $nome  ?>" class="form-control" id="inputName" placeholder="Nome"> 
          </div>

<!-- Genero -->
  <div class="form-group">
   <label for="inputGenero" class="col-sm-2 control-label">Genero</label>
     <label id="masculino">
     <input type="radio" name="genero" value="masculino">Masculino
     </label>
     <label id="feminino">
     <input type="radio" name="genero" value="feminino">Feminino
     </label>
   </div>

</form>
 <?php }  ?>
    
asked by anonymous 14.05.2016 / 13:12

2 answers

0
<input type="radio"
                <?php if (isset($genero) && $genero=="masculino") echo "checked";?>
                 name="genero" value="masculino"> Masculino
    
14.05.2016 / 16:44
0

A solution you could apply would be to use a Boolean expression inside the radius to define whether the radius is checked or not, as in the example below, where it can work for the $genero variable to be type Boolean (true or false):

Using ternary operator:

<input type="radio" <?php echo $genero ? 'checked': ''; ?>

Using if of a line:

<input type="radio" <?php if ($genero) echo 'checked'; ?>

In your code it could look like this:

   <div class="form-group">
   <label for="inputGenero" class="col-sm-2 control-label">Genero</label>
     <label id="masculino">
     <input type="radio" <?php echo $genero ? 'checked': ''; ?> name="genero" value="masculino">Masculino
     </label>
     <label id="feminino">
     <input type="radio" <?php echo $genero ? 'checked': ''; ?> name="genero" value="feminino">Feminino
     </label>
   </div>
    
14.05.2016 / 15:09