3
Good night.
I need to assemble a dynamic menu, of three tables, that need to be interconnected, but I’m lost. Follow a part of the organization chart below:
At the moment, I have the following code:
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Produtos<span class="caret"></span></a>
<ul class="dropdown-menu">
<li class="dropdown dropdown-submenu"><a class="dropdown-toggle" href="#" data-toggle="dropdown">Audiologia</a>
<ul class="dropdown-menu">
<?php
require 'conexao.php';
$consulta = $PDO->query("SELECT * FROM subcategoria WHERE categoria_id = '1' ORDER BY ID;");
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) { ?>
<li><a href="produto.php?id=<?php echo "$linha[id]"; ?>"><?php echo "$linha[titulo]"; ?></a></li>
<?php } ?>
<ul class="dropdown-menu">
<?php
require 'conexao.php';
$consulta = $PDO->query("SELECT * FROM produto WHERE categoria_id = '1' AND subcategoria_id = '1' ORDER BY ID;");
while ($linha = $consulta->fetch(PDO::FETCH_ASSOC)) { ?>
<li><a href="produto.php?id=<?php echo "$linha[id]"; ?>"><?php echo "$linha[titulo]"; ?></a></li>
<?php } ?>
</ul>
</ul>
</li>
In my database, I have the tables:
CATEGORIES = with main categories, ID and CATEGORY.
SUBCATEGORIES = with ID, CATEGORIA_ID and SUBCATEGORY fields.
PRODUCT = with ID, CATEGORIA_ID, SUBCATEGORIA_ID and TITLE fields.
I can, from this code, have the category and the sub category, but not the product. I don’t think this is the right way to do it, I’d like instructions.
I know it’s not about the question, but you don’t need to put two require for connection.
– Wictor Chaves
You’re right... I’ll correct that... is the tiredness... thank you for the touch
– Hebert Richard Masseno Dias