Note that there are some explanatory texts on larger screens.

plurals
  1. POPuzzle: How to organize a dynamic hierarchical categories menu
    primarykey
    data
    text
    <p>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.</p> <p>So I've organized my database like that, with 3 different ranks for my categories:</p> <p>I got 3 different ranks:</p> <ul> <li><p><strong>First rank:</strong> Informatics [id=1] Accessories[2] vêtements[3] Hifi ..</p></li> <li><p><strong>Second rank:</strong> Hardware[parent_key=1][id=10] software[parent_key=1][id=11] Men[parent_key=3][id=30] ..</p></li> <li><p><strong>Third rank:</strong> motherboard[parent_key=10][id=100] processor[parent_key=10][id=101] Windows7[parent_key=11][id=110] Shoes[parent_key=30][id=300] ..</p></li> </ul> <p>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 ..</p> <p>For now, I've hard-coded my menu in something like this:</p> <pre><code>&lt;div id="main_menu"&gt; &lt;ul id="nav"&gt; &lt;li class="current"&gt;&lt;a href="&lt;?php echo base_url();?&gt;"&gt;Home&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;High Tech&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Informatique&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Hardware&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Ecrans&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Clavier&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Souris&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Imprimantes&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;TV&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;LCD&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Plasma&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;3D&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Appareils Photos&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;GPS&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Smartphones&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Lecteur MP3&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Hi-Fi&lt;/a&gt; &lt;ul&gt; &lt;li&gt;&lt;a href="#"&gt;Amplificateurs&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Enceintes&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Cables&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="#"&gt;Autres&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; &lt;br class="clear" /&gt; &lt;/div&gt; </code></pre> <p>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.</p> <p>If anyone wanna help to solve this problem, he is more than welcome :)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload