Fill Select with Database data

Asked

Viewed 32 times

-1

How to Update a select input with information coming from the Database and still present the options for the person to choose to update?

$id=filter_input(INPUT_GET,'id',FILTER_SANITIZE_NUMBER_INT);

$result="SELECT * FROM banco WHERE id='$id' ";

$resultado = mysqli_query($conexao,$result);

$row = mysqli_fetch_assoc($resultado);

 <select name="motorista"         id="motorista"       placeholder="MOTORISTA" autocomplete="off"   >      
         <?php echo '<option value="'.$row_cat_post['id'].'">'.$motorista.'</option>';?>
</select><br> 

This way it only brings the stored result. N presents the primary options that made the registration. Remembering that foreign key use, then what is saved is the key that relates to the secondary bank and not the product name itself.

  • 1

    It needs a loop

1 answer

0

//vou consider que você já efetuou o inicio do codigo php e inclui a conexão com o banco atravez do "includ_once"

$id=filter_input(INPUT_GET,'id',FILTER_SANITIZE_NUMBER_INT);
$result="SELECT * FROM banco WHERE id='$id' ";
$resultado = mysqli_query($conexao,$result);
$row = mysqli_fetch_assoc($resultado);

//Deve ser inserido um laço de repetição para a cada linha do seu banco ele imprimir o resultado esperado. Neste caso vamos utilizar o while.
while ($row = $resultado->fetch_assoc()) {
   echo '<select name="motorista" id="motorista" placeholder="MOTORISTA" autocomplete="off">';
      echo '<option value="'.$row_cat_post['id'].'">'.$motorista.'</option>';
   echo '</select><br>';
}

Browser other questions tagged

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