-1
I have a screen of accounts to pay, and when I edit the data, in the option field is appearing the name of the provider (Liquigas), So far so good. But when I click on the list, the name of the supplier is appearing twice. What I might be doing wrong?
<div class="form-group col-md-10">
<label>Fornecedor</label>
<select class="form-control form-control-sm" name="cod_for">
<?php
$sql_nome_for = "SELECT nome FROM cad_for WHERE id = '$cod_fornecedor'";
$sql_nome_for = $pdo->query($sql_nome_for);
$dado_for = $sql_nome_for->fetch();
?>
<option><?php echo utf8_encode($dado_for['nome']); ?></option>
<?php
$sql_for = "SELECT id, nome FROM cad_for WHERE del <> '1' ORDER BY nome";
$sql_for = $pdo->query($sql_for);
If($sql_for->rowCount()>0){
foreach($sql_for as $fornecedor):
?>
<option value="<?php echo $dado['id_cad_for']; ?>" ><?php echo utf8_encode($fornecedor['nome']); ?></option>
<?php
endforeach;
}
?>
</select>
</div>
San, I put inside the loop, but now doubled the name.
– Fábio
Clone a condition in your query to not return the name of the first option that is before the loop, something like:
$sql_for = "SELECT id, nome FROM cad_for WHERE del <> '1' and nome <> '".$dado_for['nome']."' ORDER BY nome";
– Sam
But also put a
value
in that option out of the loop, otherwise when you save it will go empty. Something like:<option value="<?php echo $cod_fornecedor; ?>"><?php echo utf8_encode($dado_for['nome']); ?></option>
– Sam
option worked, but value is not working, it is possible to source this screen for you San?
– Fábio
The value within the loop?
– Sam
Yes, inside the loop
– Fábio
How do I leave the code of this screen here on the forum?
– Fábio
I put all the code.
– Fábio
Dude, inside the loop you put as value the
$fornecedor['id']
– Sam
You’re getting the name and id of the bank, right? The id is the value and the name is the text of the options. Nor should you edit the question.
– Sam
The option inside the loop should look like this:
<option value="<?php echo $fornecedor['id']; ?>" ><?php echo utf8_encode($fornecedor['nome']); ?></option>
– Sam
It did not work San, sorry friend, your will is great to help me, but I will study the code better, maybe make a test with only this option, just to see where I’m going wrong, thank you very much for the help.
– Fábio
Quiet. See if the answer below helps, or comment there. Abs!
– Sam