Hierarchical data PHP combobox
<p>This code works fine with the data bellow. But the Result is an Unordered lis and I would need it as a Dropdown Combobox. Does anyone nows How to do it with the SQL data and stucture in the post?</p>

<p>SQL</p>

<pre><code>CREATE TABLE IF NOT EXISTS `categories` (
  `catid` int(3) NOT NULL AUTO_INCREMENT,
  `catname` varchar(45) NOT NULL,
  `catparent` int(3) NOT NULL,
  `catorder` int(4) NOT NULL,
  `catdesc` varchar(1024) NOT NULL,
  PRIMARY KEY (`catid`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1;

--
-- Dumping data for table `categories`
--

INSERT INTO `categories` (`catid`, `catname`, `catparent`, `catorder`, `catdesc`) VALUES
(1, 'Informática', 0, 1000, 'Computadores e acessórios'),
(2, 'Comunicações', 0, 1000, 'Sistemas de Comunicações'),
(3, 'Acessórios', 1, 2000, 'Acessórios para Computadores'),
(4, 'PABX', 2, 2000, 'Centrais telefónicas IP e TDM'),
(5, 'Controle de Acessos', 0, 1000, 'Controle de Acessos e Assiduidade'),
(6, 'Construção Civil', 0, 1000, 'Construçao Civil    ');
</code></pre>

<p>Code</p>

<pre><code>  &lt;?php
  include '../lib/configuration.php';

  $mysqli = new mysqli($dbhost, $dbuser, $dbpwd, $database);

  /* check connection */
  if (mysqli_connect_errno()) 
  {
      printf("Connect failed: %s\n", mysqli_connect_error());
      exit();
  }

  $query = "SELECT * FROM categories";
  if ($result = $mysqli-&gt;query($query)) 
  {

    /* fetch associative array */
    while($row = $result-&gt;fetch_assoc())
    { 
      $arrayCategories[$row['catid']] = array("pid" =&gt; $row['catparent'], "name" =&gt;  $row['catname']);   
    }

    //createTree($arrayCategories, 0);
    function createTree($array, $currentParent, $currLevel = 0, $prevLevel = -1) 
    {
      foreach ($array as $categoryId =&gt; $category) 
      {
        if ($currentParent == $category['pid']) 
        {                       
            if ($currLevel &gt; $prevLevel) echo " &lt;ul&gt; "; 
            if ($currLevel == $prevLevel) echo " &lt;/li&gt; ";
            echo '&lt;li id="'.$categoryId.'" onclick=child(this.id);&gt;&lt;span&gt;'.$category['name'].'&lt;/span&gt;';
            if ($currLevel &gt; $prevLevel) { $prevLevel = $currLevel; }
            $currLevel++; 
            createTree ($array, $categoryId, $currLevel, $prevLevel);
            $currLevel--;               
        }   
      }
      if ($currLevel == $prevLevel) echo " &lt;/li&gt;  &lt;/ul&gt; ";
    }   
?&gt;
&lt;div id="content" class="general-style1"&gt;
&lt;?php
   if($result-&gt;num_rows!=0)
   {
  ?&gt;
  &lt;ul&gt;
      &lt;li id="0" class="root"&gt;&lt;span&gt;Categories&lt;/span&gt;
      &lt;?php createTree($arrayCategories, 0); ?&gt;
  &lt;/li&gt;
  &lt;/ul&gt;
  &lt;?php
    }
  }
  ?&gt;
&lt;/div&gt;
</code></pre>
