Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Okay, thanks for all you post, but I found a way to deal with my problem, here my personal solution :</p> <p>So I first begin by retrieving all the categories in a array : "allCategories"</p> <p>Then, while I build the menu, with while loops and if conditions, I get what I want :</p> <p>so we have, for each category</p> <ul> <li><p>Category['cat_id'] which is the id of the category</p></li> <li><p>Category['cat_title'] the name of the cat </p></li> <li><p>Category['cat_order'] the rank of the category</p></li> <li><p>Category['cat_parentkey'] the id of the parent of my categorie (Parent of motherboad: Hardware)</p> <pre><code>$token1=TRUE; $token2=TRUE; foreach($allCategories as $Categories1){ //we are going to check all the cats :: on fait defiler toutes les catégories if($Categories1['cat_order']==1){ // if its rank 1 :: si le rang de la categorie est 1 $key = $Categories1['cat_id']; // we save its ID echo '&lt;li&gt;&lt;a href="#"&gt;'; echo $Categories1['cat_title']; echo '&lt;/a&gt;'; // this is the loyaout to print the list, the /li comes further :: on fait la mise en page pour afficher la liste, le /li venant plus bas foreach($allCategories as $Categories2test){ // We gonna check if there is AT LEAST ONE categorie with an inferior rank, otherwise we do not print the &lt;ul&gt; which produce an ugly bar next to the menu :: on va tester si il existe AU MOINS UNE catégorie de rang inférieur, sinon on n'affiche pas de ul afin d'éviter une barre moche dans le menu if($Categories2test['cat_order']==2 AND $Categories2test['cat_parentkey']==$key AND $token1==TRUE){ // We do a test with a token which, once we do 1 loop inside, tell us there is at least one cat with an inferior rank :: on fait donc un test avec un token qui, une fois qu'on passe dedans 1 fois, nous dis qu'i'il y a donc au moins un rang inféireur echo '&lt;ul&gt;'; // layout of our menu, is printed only if there is inferioir cats :: mise en forme du sous menu, ne s'affiche donc qu si il ya une categorie de ranf inferieur. foreach ($allCategories as $Categories2){ // One again, we check all the cats :: on fait défiler les catégories if($Categories2['cat_order']==2 AND $Categories2['cat_parentkey']==$key){ // If there is at least one of rank 2 so .... :: si il y en a 1 de rang 2 alors ... $key2 = $Categories2['cat_id']; echo '&lt;li&gt;&lt;a href="#"&gt;'; echo $Categories2['cat_title']; echo '&lt;/a&gt;'; foreach($allCategories as $Categories3test){ if($Categories3test['cat_order']==3 AND $Categories3test['cat_parentkey']==$key2 AND $token2==TRUE){ echo "&lt;ul&gt;"; foreach ($allCategories as $Categories3){ if($Categories3['cat_order']==3 AND $Categories3['cat_parentkey']==$key2){ $key3 = $Categories3['cat_id']; echo '&lt;li&gt;&lt;a href="#"&gt;'; echo $Categories3['cat_title']; echo '&lt;/a&gt;'; echo "&lt;/li&gt;"; } } echo "&lt;/ul&gt;"; $token2=FALSE; } } echo"&lt;/li&gt;"; } $token2=TRUE; } echo'&lt;/ul&gt;'; $token1=FALSE; // We put our token to FALSE in order to avoid that loop for that particular rank1 category :: on met notre token à FALSE afin de ne plus refaire cette boucle pour cette catégorie de rang1 } } echo "&lt;/li&gt;"; } $token1=TRUE; // We put the token to TRUE in order to do that loop again for the other rank 1 categorie :: on remet le token à 0 afin de repasser dans la boucle pour la catégorie de rang 1 suivante } </code></pre> <p>?></p></li> </ul>
 

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