I'm trying to develop a hierarchical menu in my e-commerce website in which my categories are dynamically shown in order to add more categories without having to touch the code.
So I've organized my database like that, with 3 different ranks for my categories:
I got 3 different ranks:
First rank: Informatics [id=1] Accessories[2] vêtements[3] Hifi ..
Second rank: Hardware[parent_key=1][id=10] software[parent_key=1][id=11] Men[parent_key=3][id=30] ..
Third rank: motherboard[parent_key=10][id=100] processor[parent_key=10][id=101] Windows7[parent_key=11][id=110] Shoes[parent_key=30][id=300] ..
So you've understood that the "parent_key" refers to the parent id of my category abd for each category of rank 1 I got several rank 2 categories and so on ..
For now, I've hard-coded my menu in something like this:
<div id="main_menu">
<ul id="nav">
<li class="current"><a href="<?php echo base_url();?>">Home</a></li>
<li><a href="#">High Tech</a>
<ul>
<li><a href="#">Informatique</a>
<ul>
<li><a href="#">Hardware</a></li>
<li><a href="#">Ecrans</a></li>
<li><a href="#">Clavier</a></li>
<li><a href="#">Souris</a></li>
<li><a href="#">Imprimantes</a></li>
</ul>
</li>
<li><a href="#">TV</a>
<ul>
<li><a href="#">LCD</a></li>
<li><a href="#">Plasma</a></li>
<li><a href="#">3D</a></li>
</ul>
</li>
<li><a href="#">Appareils Photos</a></li>
<li><a href="#">GPS</a></li>
<li><a href="#">Smartphones</a></li>
<li><a href="#">Lecteur MP3</a></li>
<li><a href="#">Hi-Fi</a>
<ul>
<li><a href="#">Amplificateurs</a></li>
<li><a href="#">Enceintes</a></li>
<li><a href="#">Cables</a></li>
<li><a href="#">Autres</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<br class="clear" />
</div>
I'm coding in MVC, and I don't know exactly how to build my model, my controller, and my view. I guess I'll have to do some if/else and foreach loop but I can't figure it out by myself.
If anyone wanna help to solve this problem, he is more than welcome :)