Well, I'm going to try to be specific here, I need to display all the categories and subcategories of levels 1, 2 and 3 that exist in the bank.
I have achieved this so far, but when he does not find anything on the referring bench, he breaks the html. Could someone give me an aid?
Mycodesofarislikethis.
<tr><!--CHAMANDOCATEGORIA--><?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; ?>