Hi there,

I'm struggling with the logic for displaying a category tree as standard compliant nested <ul> tags and I was hoping someone could offer me a solution

It is a tree of product categories which can be infinitely deep. I have a function which will get the full category tree in the correct order. For each row it will also tell me how many levels deep that category is. For example, if retrieving just the category name and level it would look something like this:

Clothing 1
Trousers 2
Mens trousers 3
Ladies trousers 3
Jackets 2
Shirts 2
Shoes 2
Mens shoes 3
Mens formal shoes 4
Mens casual shoes 4
Kids shoes 3
Ladies shows 3
Cars 1
Small cars 2
etc etc

If put a space before each category name foreach level then it looks like a tree:

Code:
Clothing 1
 Trousers 2
   Mens trousers 3
   Ladies trousers 3
 Jackets 2
 Shirts 2
 Shoes 2
  Mens shoes 3
   Mens formal shoes 4
   Mens casual shoes 4
  Kids shoes 3
  Ladies shoes 3
Cars 1
 Small cars 2
I want to use a good coding structure though and the tree will be best presented as a <ul>. So something like this:

HTML Code:
<ul>
  <li>Clothing 1
    <ul>
      <li>Trousers 2
        <ul>
          <li>Mens trousers 3</li>
          <li>Ladies trousers 3</li>
        </ul>
      </li> 
      <li>Jackets 2</li>
      <li>Shirts 2</li>
      <li>Shoes
        <ul>
          <li>Mens shoes 3
            <ul>
              <li>Mens formal shoes 4</li>
              <li>Mens casual shoes 4</li>
            </ul>
          </li>
          <li>Kids shoes 3</li>
          <li>Ladies shoes 3</li>
        </ul>
      </li>
    </ul>
   </li>
  <li>Cars 1
   <ul>
     <li>Small cars 2</i>
   </ul>
  </li>
</ul>
I think I've just got that right So is that possible just through using the value of the level number. I've been trying to echo tags based on the value of level changing but I just can't get it right.

Many thanks