What's wrong with this PHP Recursive Function?
<p>I have a database table with the following data:</p>

<pre><code>categoryId    categoryName    parentCategory
men           Men             root
women         Women           root
shoes         Shoes           root
mensshirts    Men's Shirts    men
menspants     Men's Pants     men
mensjeans     Men's Jeans     men
mensvests     Men's Vests     men
womensshirts  Women's Shirts  women
womenpants    Women's Pants   women
</code></pre>

<p>I'm using a recursive function to print out a tiered menu. The code is below.</p>

<pre><code>function display_children($parent) {
    global $connect;
    $query = "SELECT categoryId, categoryName FROM categories WHERE parentCategory='$parent'";
    $result = mysqli_query($connect,$query);

    if ( $result === false ) {
       printf("Query Error: %s\n", mysqli_error($connect));
       exit();
    }

    echo "&lt;ul&gt;";
    while ($row = mysqli_fetch_assoc($result)) {
       extract($row);
       echo "&lt;li&gt;".$categoryName."&lt;/li&gt;";
       display_children($categoryId);   
    }
    echo "&lt;/ul&gt;";

    mysqli_close($connect);
}

display_children('root');
</code></pre>

<p>As a result, I get this printed out on screen:</p>

<ul>
<li>Men
<ul>
<li>Men's Shirts</li>
<li>Men's Pants</li>
<li>Men's Jeans</li>
<li>Men's Vests</li>
</ul></li>
<li>Women</li>
<li>Shoes</li>
</ul>

<p>The recursive function is not printing out the rest of the subcats, and I'm not sure why. My testing/debugging has confirmed that after mensvests is passed as a categoryId into the function, the next categoryId passed is women, which should locate the last subcats. Any ideas?</p>
