I'm having a problem with looping
, I'm working with 3 Bank tables, it would be Anuncio
, Opcoes_Anuncio
( interleave) and Opcoes
, I'm trying to get data from options together with the selected options, but it happens that you are giving multiple looping
.
MYSQL
My query is like this
SELECT * FROM
opcoes
op
INNER JOIN
opcoes_anuncio
oa
ON
oa
.opcoes_id_opcao
op
.id_opcao
INNER JOIN
anuncio
an
ON
oa
.anuncio_id_anuncio
=an
.id_anuncio
WHERE
an
.anuncio_id_anuncio
= '17'
ORDER BY
op
.id_opcao
ASC
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; ?>