Hi all,

I've got a table that determines a category/sub-category relationship using id and parentId.

Using MySQL I have been able to output the order of the Category/Sub-Category relationship into an Array:

Code PHP:
Array
(
    [1] => Array
        (
            [0] => 
            [1] => Test Category
            [2] => 1
        )
 
    [4] => Array
        (
            [0] => 1
            [1] => Sub Category 1
            [2] => 2
        )
 
    [5] => Array
        (
            [0] => 1
            [1] => Sub Category 3
            [2] => 2
        )
 
    [6] => Array
        (
            [0] => 1
            [1] => Sub Category 4
            [2] => 2
        )
 
    [2] => Array
        (
            [0] => 
            [1] => Test Category 2
            [2] => 1
        )
 
    [3] => Array
        (
            [0] => 2
            [1] => Sub Category 2
            [2] => 2
        )
 
)

and using the following I am generating a List which when put into my page, css styles it into a menu.

Code PHP:
        function RenderCategoryMenu() {
            $data = dataAccess::getCartCategories(null, array(), 1);
            if(isset($data) && count($data) > 0) {
                $rv = "<ul id=\"leftMenu\">\n\t";
                foreach($data as $i => $value) {
                    if(isset($value[0]))
                        $rv .= "<ul>\n\t";
                    $rv .= "<li><a href=\"#" . $i . "\">" . $value[1] . "</a>\n\t";
                    if(isset($value[0]))
                        $rv .= "</ul>";
                    $rv .= "</li>";
                }
                return $rv . "</ul>";
            } else
                return "<ul id=\"leftMenu\"><li><a>No Categories</a></li></ul>";
        }

Using the above Array and function, I get

Code HTML4Strict:
<ul id="leftMenu">
    <li><a href="#1">Test Category</a></li>
        <ul>
            <li><a href="#4">Sub Category 1</a>
        </ul>
    </li>
        <ul>
            <li><a href="#5">Sub Category 3</a>
        </ul>
    </li>
        <ul>
            <li><a href="#6">Sub Category 4</a>
        </ul>
    </li>
    <li><a href="#2">Test Category 2</a></li>
        <ul>
            <li><a href="#3">Sub Category 2</a>
        </ul>
    </li>
</ul>


But my problem is that each subcategory item has its own UL where it should be all subcategories in one UL.

ie

Code HTML4Strict:
<ul id="leftMenu">
    <li><a href="#1">Test Category</a>
        <ul>
            <li><a href="#4">Sub Category 1</a></li>
            <li><a href="#5">Sub Category 3</a></li>
            <li><a href="#6">Sub Category 4</a></li>
        </ul>
    </li>
    <li><a href="#2">Test Category 2</a>
        <ul>
            <li><a href="#3">Sub Category 2</a></li>
        </ul>
    </li>
</ul>

Can anyone help me achieve this?