destoon分类树状列表

来源: https://destoon.cc/ 日期: 2019-03-01 22:16:28 人气: - 评论: 0

 在使用destoon的过程中要制作一些小工具,会用到模块下的分类,如果使用系统自己带的,需要引入一大批js,对于小工具来说就有点臃肿了
那么如何调用来他的分类列表出来呢,制作了一个小函数

具体代码与使用方法见下方
 

  1. <?  
  2. define('IN_DESTOON', true);  
  3. require 'common.inc.php';  
  4.   
  5.   
  6. function InitClassSelectOption($ParentID,$ChkID,$db)  
  7. {  
  8.     $sql="SELECT * from dt_category where moduleid=5 and  parentid=".$ParentID;  
  9.    
  10.     $options="";  
  11.     $result = $db->query($sql);  
  12.     //$r = $db->fetch_array($result);  
  13.     //var_dump($r);  
  14.     while($r = $db->fetch_array($result))  
  15.     {  
  16.          echo "<option ";  
  17.          if($ChkID==$r['catid']) echo " selected='selected' ";  
  18.          echo ">";  
  19.          $parent=$r["arrparentid"];  
  20.          $tmp=explode(",",$parent);  
  21.          for($i=0;$i<count($tmp);$i++)  
  22.         {   
  23.              echo "  ";  
  24.         }  
  25.          echo  "├" . $r['catname']." </option>";  
  26.          InitClassSelectOption($r["catid"],$ChkID,$db);  
  27.   
  28.     }  
  29. }  
  30. ?>  
  31. <select>  
  32. <?php  
  33. echo InitClassSelectOption(0,18,$db);  
  34. ?>  
  35. </select>