I'm doing a dynamic php menu where I would not use a query inside another, I'm currently looking at the CATEGORY table of the category name and inside it I'm searching in another table for the results that I have in the category field, in the CATEGORY table. Is there anything that shortens this code? or way to query directly on the table that can give the same result?
Menu example:
// primeira consulta pego da tabela categoria todos os tipos de categorias que existe
$results = mysqli_query($db, "SELECT * FROM categorias");
//faco o loop
while ($row = mysqli_fetch_array($results)) {
// defino a categoria
$categoria = $row['titulo'];?>
// imprimo o nome do menu
<li> <a href="#homeSubmenu" data-toggle="collapse" aria-expanded="false">
<?php echo $row['titulo']; ?></a>
/// abro a categoria sub menu
<ul class="collapse list-unstyled" id="homeSubmenu">
// faco a segunda consulta
<? $results = mysqli_query($db, "SELECT * FROM paginas WHERE categoria = '$categoria' ");
while ($row = mysqli_fetch_array($results)) { ?>
<li><a href="#"><?php echo $row['titulo']; ?></a></li>
// fecho as 2 consultas
<?php }} ?>
Oh yeah as for the title CONSULTA WITH PAUSE, it was something that I thought could give a certain type to each result of the 1st query to execute the second one automatically, the logic seems simple but the execution is complicated.