Hello, I'm trying to list Sub-Categories within their respective Categories with Inner Join, but I'm not getting it, see what's happening with the Categories menu.
Below is the code used ...
<?php
include "../conexao.php";
$codigo = $_POST['codigo'];
$nome_cat = $_POST['nome_cat'];
$nome = $_POST['nome'];
$query = mysql_query("SELECT * FROM categoria INNER JOIN sub_categoria ON categoria.nome_cat = sub_categoria.nome_cat")or die(mysql_error());
while ($res = mysql_fetch_array($query)){
?>
<ul>
<li><a href="#"> <?php echo $nome_cat = $res['nome_cat'];?> </a>
<ul>
<li><a href="prod_index_categoria.php?codcategoria=<?php echo $res['nome'];?>"><?php echo $res['nome'];?></a></li>
</ul>
</li>
<?php
}
?>
</ul>
Below I relate images of the structures of the tables ...
Category:
Sub-Category:
If friends can help me solve the problem by making Categories not duplicate, and Sub-Categories stay within their Categories, I'll be very grateful.