Hello, I've created a menu that looks for the information in the database. I have a table with the categories and another one with the subcategories, so my beauty is that it is difficult to have each subcategory listed in its category (example below) ...
ButI'mnotgettingit,itlooksliketheexamplebelow...
BelowI'mattachingthecodeusedforthemenu...
<?phpinclude"../conexao.php";
$codigo = $_POST['codigo'];
$nome = $_POST['nome'];
$query = mysql_query("SELECT * FROM categoria order by nome")or die(mysql_error());
while($res = mysql_fetch_array($query)){
?>
<ul>
<li><a href="#"> <?php echo $res['nome'];?> </a>
<?php
}
?>
<?php
include "../conexao.php";
$nome = $_POST['nome'];
$query = mysql_query("SELECT * FROM sub_categoria order by nome")or die(mysql_error());
while($res = mysql_fetch_array($query)){
?>
<ul>
<li><a href="prod_index_subcategoria.php?codsubcategoria=<?php echo $res['nome'];?>"><?php echo $res['nome'];?></a></li>
</ul>
</li>
<?php
}
?>
</ul>
Below table structures used ... Categories:
Subcategories:
Products:
IffriendscanhelpmebytellingmewhereI'mgoingwrong,orevenwhattodosothatIcanreachmygoal,whichareSubcategoriesbeinglistedwithintheirrespectiveCategories.
Iamwaitingforthehelpofmyfriends,andthankyouforyourattention.
I'meditingthePostwiththenewlineofcodebelowwithInnerJoin...
<?phpinclude"../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 $res['nome_cat'];?> </a>
<ul>
<li><a href="prod_index_subcategoria.php?codsubcategoria=<?php echo $res['nome'];?>"><?php echo $res['nome'];?></a></li>
</ul>
</li>
<?php
}
?>
</ul>
And I'm also attaching the images of the Categories and Sub-Categories structures that I got wrong before and published the category duplicity.
Category:
Sub-Category: