【问题标题】:Create TreeView Dropdown List创建 TreeView 下拉列表
【发布时间】:2020-02-06 12:25:14
【问题描述】:

我的问题是,我希望我的输出以
下拉列表(树视图结构)的形式显示在 select 标记 中,而且我也想要选择多个类别 借助使用 html 标签,即 Checkbox

<?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);
?>

这里的输出:- enter link description here

【问题讨论】:

    标签: javascript php html css mysql


    【解决方案1】:

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

    if (mysqli_num_rows($result) > 0) {

        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>";
      }
    }
    

    【讨论】:

    • 感谢您的回答,但这不是正确的答案。我希望单个选择标记中显示的所有类别都是树视图结构。请参阅此链接google.com/…
    • 参考这个demo树视图并自定义上面的代码,希望这能按预期工作
    猜你喜欢
    • 2014-12-15
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多