Javascript 创建树视图下拉列表

Javascript 创建树视图下拉列表,javascript,php,html,css,mysql,Javascript,Php,Html,Css,Mysql,我的问题是,我希望我的输出以 下拉列表(树状视图结构),我还想选择多个类别 在使用html标记的帮助下,例如,复选框 <?php function getCategory($parent_id){ $con = connect_db(); $sql = "select ocd.category_id,ocd.name, occ.parent_id from oc_category_description ocd, oc_category occ where ocd.cate

我的问题是,我希望我的输出以
下拉列表(树状视图结构),我还想选择多个类别 在使用html标记的帮助下,例如,复选框

<?php
function getCategory($parent_id){
    $con = connect_db();
    $sql = "select ocd.category_id,ocd.name, occ.parent_id from oc_category_description ocd, oc_category occ where ocd.category_id=occ.category_id and  parent_id='".$parent_id."' ORDER BY name";
    $result = mysqli_query($con,$sql);

      if (mysqli_num_rows($result) > 0)
      {

        echo "<ul>";
          while ($row = mysqli_fetch_object($result))
          { 
           echo "<li>".$row->name.'('.$row->category_id.')'."</li>";
           getCategory($row->category_id);     
         }
        echo "</ul>";
      }
    }
$parent_id = 0;
getCategory($parent_id);
?>

以下是输出:-

您可以用这些代码行在下拉列表中显示结果。希望这是您想要的

如果(mysqli_num_行($result)>0) {

echo';
while($row=mysqli\u fetch\u object($result))
{ 
回显“$row->name.”(“$row->category_id.”);
getCategory($row->category\u id);
}
回声“;
}
}

感谢您的回答,但这不是正确的答案。我希望使用is树状视图结构的单个select标记中显示的所有类别。请参阅此链接,参考此树状视图并自定义上述代码,希望这能按预期工作
    echo '<select name="nameUwanted">';
      while ($row = mysqli_fetch_object($result))
      { 
       echo "<option value='". $row->name ."'>" .$row->name.'('.$row->category_id.')'."</option>" ;
       getCategory($row->category_id);     
     }
    echo "</select>";
  }
}