List data for Options

Asked

Viewed 72 times

1

I’m trying to list database data for my options, but I don’t know how to do it I tried it the following way down there, I want that when the form is sent I want to send the ID from that location, but in select I want you to show the descrição that id.

//criei a query = $consulta
  $consulta = "SELECT denuncia.id, data, imagem ,denuncia.descricao, b.descricao as bloco_descricao, doq.descricao as oque_descricao, id_bloco, id_denuncia_oque, qual_descricao, u.matricula, nome, sobrenome FROM denuncia INNER JOIN usuario u ON u.id = denuncia.id_usuario INNER JOIN bloco b ON b.id = denuncia.id_bloco INNER JOIN denuncia_oque doq ON doq.id = denuncia.id_denuncia_oque";
   //prepara a query
   $con = $connection->prepare($consulta);
   //executar o comando sql
   $denuncia = $con->execute();
   //juntar todos os resultados do select em um vetor de arrays
   $denuncia = $con->fetchAll();

Here are my Options

<select select="required" class="form-control" name="id_denuncia_oque" id="sel1" required="required" >
    <option value="" disabled selected>Ex: Laboratório</option>
    <?php  foreach ( $denuncia as $den   )  {  ?>                    
        <option value="<?$den["id_denuncia_oque"]; ?>"> 
            <?php echo $den["oque_descricao"]; ?>
        </option>
    <?php }?>
</select>
  • Are you using some framework or are pure php?

  • 3

    It would be convenient to [Dit] the question better describing your problem (what result you expected, and what result came out instead). Take the time to put the HTML generated by PHP.

  • Well what I wanted to do was list the database data for these Options, I have a table called complaint _oque, that its fields are id and Description. What I wanted to do was list the description of this table for my Options, but when my form was sent I did not want to send the description but the id of the description.

  • This Select ai from the bank was from my other page, and there are many fields that I will not need to use on this page.

  • The way it’s there doesn’t work because? Like, there’s the id_denuncia_oque no value of option, right?

  • I forgot but this id_denuncia_oque is where the data of the id of the denounce_oque table will be stored

  • Was there an error in php? What was the result in your HTML page?

Show 2 more comments
No answers

Browser other questions tagged

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