0
Guys, I’m going to try to be specific here, I need to show all the categories and subcategories of level 1, 2 and 3 that exist in the bank.
I got it so far, but when he can’t find anything in the referring bank, he breaks the html. Could someone give me a hand?
My code so far is like this.
<tr>
<!--CHAMANDO CATEGORIA-->
<?php
$select_cat = "SELECT * FROM categoria_recursiva WHERE nivel = 0";
$res_selectCat = $conn->query($select_cat);
while($colCat = mysqli_fetch_assoc($res_selectCat)):
$idCat = $colCat['id'];
?>
<td> <?= $colCat['nome']; ?> </td>
<!--CHAMANDO A SUBCATEGORIA 1-->
<?php
$select_subcat1 = "SELECT * FROM categoria_recursiva WHERE id_pai = $idCat";
$res_selectSub1 = $conn->query($select_subcat1);
while($colSub1 = mysqli_fetch_assoc($res_selectSub1)):
$idSub1 = $colSub1['id'];
?>
<td> <?= $colSub1['nome']; ?> </td>
<!--CHAMANDO A SUBCATEGORIA 2-->
<?php
$select_sub2 = "SELECT * FROM categoria_recursiva WHERE id_pai = '$idSub1'";
$res_selectSub2 = $conn->query($select_sub2);
while($colSub2 = mysqli_fetch_assoc($res_selectSub2)):
$idSub2 = $colSub2['id'];
?>
<td> <?= $colSub2['nome'];?> </td>
<!--CHAMANDO A SUBCATEGORIA 3-->
<?php
$select_sub3 = "SELECT * FROM categoria_recursiva WHERE id_pai = '$idSub2'";
$res_selectSub3 = $conn->query($select_sub3);
while($colSub3 = mysqli_fetch_assoc($res_selectSub3)):
$idSub3 = $colSub3['id'];
?>
<td> <?= $colSub3['nome'];?> </td>
<?php endwhile; ?>
<?php endwhile; ?>
<td>
<button class="btn btn-info" type="submit" data-toggle="modal" data-target="#painel-editar<?= $colCat['id']; ?>" data-placement="top" title="" data-original-title="Editar"><i class="fa fa-edit"></i> </button>
<button class="btn btn-danger" type="submit" data-toggle="modal" data-target="#painel-remover<?= $col_cat['id']; ?>" data-placement="top" title="" data-original-title="Apagar"><i class="fa fa-close"></i> </button>
</td>
</tr><?php endwhile; ?>
Enter the code, not an image of it. The site has support for this.
– João Pedro Schmitz
Apparently the number of
<td>
is different for each<tr>
on your table.– fernandosavio
I just edited by going up the code
– Caio Brandão