1
I’m having a problem looping, I am working with 3 tables of the Bank, would be table Anuncio, Opcoes_Anuncio(interconnected) and Opcoes, I’m trying to bring the option data along with the selected options, but it turns out it’s giving several looping.
MYSQL
my query is like this
SELECT * FROMopcoesopINNER JOINopcoes_anunciooaONoa.opcoes_id_opcao=op.id_opcaoINNER JOINanuncioanONoa.anuncio_id_anuncio=an.id_anuncioWHEREan.anuncio_id_anuncio= '17'ORDER BYop.id_opcaoASC
PHP
<?php foreach ($opcoes as $val): ?>
<div class="form-group form-check">
<input type="checkbox" class="form-check-input" name="opcoes_id_opcao[]"
value="<?= $row->id_opcao; ?>"
id="<?= $row->slug_opcao; ?>"
<?php if($row->id_opcao == $val->opcoes_id_opcao) { echo "checked"; }?> >
<label class="form-check-label" for="<?= $row->slug_opcao; ?>">
<?= $row->titulo_opcao; ?>
</label>
</div>
<?php endforeach; ?>
<?php endforeach; ?>

What’s your idea in this loop?
– Wees Smith
You have to describe much more to get a satisfactory answer. what you have
$show_opcoes? and what has$opcoes? what html result these two for’s give and what would be the right one ?– Isac
Okay, I had forgotten to upload the image, with it becomes much easier to visualize the error that happens
– Alexandre Xavier
In your SQL you have an error, here should be
WHERE an.id_anuncio, but other than that the query does not return duplicated records unless they have actually been recorded the same ad option more than once. Post the code of your 2foreach, the problem must be there.– Dobrychtop
I think it is error in the same Foreach, but I’m trying to bring the normal values that would OPTIONS and also bring the chosen marked values before it is OPCOES_ANUNCIOS, when I do right, it only returns me the 3 marked, but I need the OPTIONS values so that the person selects another option
– Alexandre Xavier