0
Dear ones, I have designed this code snippet so that the data received from my SQL SERVER database is listed in a select via PDO:
consultationphp.:
<form name="cargo" method="post" action="consultacargos.php">
<label for="">Selecione um Cargo</label>
<select>
<option>Selecione...</option>
<?php
$consulta = $conn->query("SELECT * FROM [DB].[Cargos] order by Codigo");
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) { ?>
<option name ='selecao' value="<?php echo $linha['codigo'] ?>"><?php echo $linha['descricao'] ?></option>
<?php } ?>
</select>
<button type="submit">Selecionar</button>
So far so good, the options appeared on the list of select right, only what I wish is that when selecting one of the options it is printed in the same page with an 'echo', you can help me?
I believe it is something simple, but I am in the process of learning and I was indicated to seek help in the stack for learning. Thanks in advance.
By the time the page is delivered to the browser, the php service is over. I suggest studying server-side vs client-side code in web development.
– bfavaretto