Select multiple options in select

Asked

Viewed 317 times

3

I have this select:

<div>
<label for="Indicar">Colaborador: </label>
<select class="form-control" name="Notas" id="Notas26">
      <option></option>
      <?php        
         $sql = "SELECT * FROM raddb.usuarios ORDER BY nome ASC";
         $qr = mysqli_query($conn, $sql);
         while($ln = mysqli_fetch_assoc($qr)){
            echo '<option value="'.$ln['id'].'">'.$ln['nome'].'</option>';
         }
      ?>        
</select>
</div>

Within the select several collaborators will appear. I want to be able to select several collaborators.

I tried to follow this question, but I couldn’t implement.

  • 1

    Just put multiple in select.

  • @Sam, yes I have. I was trying to use the code of your answer, because Multiple, creates a very large box, but I solve with css

1 answer

3


Try adding the attribute multiple in his select. The attribute multiple is a boolean attribute that when present, specifies that several options can be selected at once.

<div>
<label for="Indicar">Colaborador: </label>
<select class="form-control" name="notas[]" id="Notas26" multiple>
      <option></option>
      <?php        
         $sql = "SELECT * FROM raddb.usuarios ORDER BY nome ASC";
         $qr = mysqli_query($conn, $sql);
         while($ln = mysqli_fetch_assoc($qr)){
            echo '<option value="'.$ln['id'].'">'.$ln['nome'].'</option>';
         }
      ?>        
</select>
</div>

To manipulate the selected values in php:

foreach ($_POST['notas'] as $nota)  
    print "Você selecionou $nota<br/>"; 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.