title: How to create unlimited sub category in drop down list
body: <p>Would you please guide me on how to create unlimited category and sub category in a drop down list using php and mysql?</p>
  
  <p>I was the sub category to have --- in front of them. For example, the first sub category --- and the second level ----- and so on:
  I want to achieve some thing like this:-</p>
  
  <pre><code>&lt;select name="category"&gt;
  &lt;option value="1"&gt;Root&lt;/option&gt;
  &lt;option value="3"&gt;- Sub &lt;/option&gt;
  &lt;option value="4"&gt;- - Sub&lt;/option&gt;
  &lt;option value="5"&gt;Root&lt;/option&gt;
  &lt;option value="6"&gt;- Sub &lt;/option&gt;
  &lt;option value="7"&gt;- - Sub&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>Here is the code I got so far</p>
  
  <pre><code>function get_category($parentID = 0){
    global $mysqli;
    $html = '';
    // Prepare the query
    $stmt = $mysqli-&gt;prepare("SELECT CategoryID, Title
                              FROM category
                              WHERE ParentID =?");
    // Bind param
    $stmt-&gt;bind_param('i', $parentID);
  
    // Execute the query
    $stmt-&gt;execute();
  
    // Store the result
    $stmt-&gt;store_result();
  
    // Bind the result
    $stmt-&gt;bind_result($categoryID, $title);
    while($stmt-&gt;fetch()){
      $html .= "&lt;option value=\"$categoryID\"&gt;$title&lt;/option&gt;";
  
      $child = $mysqli-&gt;prepare("SELECT CategoryID
                                 FROM category
                                 WHERE ParentID =?");
  
      // Execute the query
      $child-&gt;bind_param('i', $categoryID);
      $child-&gt;execute();
  
      // Store the result
      $child-&gt;store_result();
  
      // Bind the result
      $has_child = NULL;
      $has_child = $child-&gt;num_rows;
      if($has_child){
        $html .= get_category($categoryID); 
      }
    }
  
    return $html;
  }
  echo '&lt;select name="category"&gt;';
  print(get_category());
  echo '&lt;/select&gt;';
  </code></pre>
  
  <p>Any help is appreciated </p>