I have a couple fields in my database; FilePath and FileName
Now, let's say I pull all rows from my database, and this is what I get: (FilePath and FileName are put together, and it is sorted by FilePath, FileName).
DRINK/coffee.php
DRINK/milk.php
DRINK/SODA/DARK/cola.php
DRINK/SODA/DARK/rootbeer.php
DRINK/SODA/LIGHT/gingerale.php
FOOD/chicken.php
FOOD/chips.php
FOOD/FRUIT/apples.php
FOOD/FRUIT/oranges.php
FOOD/popcorn.php
My goal is to end up with this:
Code: Select all
<li>DRINK
<ul>
<li>coffee.php</li>
<li>milk.php</li>
<li>SODA
<ul>
<li>DARK
<ul>
<li>cola.php</li>
<li>rootbeer.php</li>
</ul>
</li>
<li>LIGHT
<ul>
<li>gingerale.php</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>FOOD
<ul>
<li>chicken.php</li>
<li>chips.php</li>
<li>FRUIT
<ul>
<li>apples.php</li>
<li>oranges.php</li>
</ul>
</li>
<li>popcorn.php</li>
</ul>
</li>I've tried pulling only DISTINCT FilePath's from the database. Going through each FilePath, breaking them apart and storing those parts in an array to get the levels right. Then, I check if the current level's path name matches the last. If not, I create a new list. Unfortunately, I don't know how to let it know when to close the list tag.
I appreciate any help I can get. Thanks.