http://www.treejs.cn/v3/main.php#_zTreeInfo
来自网上:
1 <?php
2 header("content-type:text/html;charset=utf-8");
3 $menu.= "<select id='sel'>";
4 function tree_set($index)
5 {
6 global $menu,$str;
7 static $j;
8 $cn=mysql_connect("127.0.0.1","root","root");
9 $db=mysql_select_db("test");
10 $sql = "SELECT * FROM category WHERE parent={$index} AND class_id=1";
11 mysql_query("set names utf8");
12 $q = mysql_query($sql);
13 if(!mysql_num_rows($q)){
14 return;
15 }
16 $j=$j+1;
17 while($arr=mysql_fetch_assoc($q))
18 {
19 //echo $j;
20 for ($i = 0 ; $i < $j; $i++){
21 $str .= '|';//几级菜单几条竖线
22 }
23 $str.= '---';
24 $menu.= "<option value=".$arr['cat_id'].">";
25 $menu.= $str.$arr['cat_name'];
26 $menu.= '</option>';
27 $str = '';
28 tree_set($arr['cat_id']);
29 }
30 $str = '';
31 }
32 function write_html()
33 {
34 global $menu;
35 tree_set(0);
36 $menu.= '</select>';
37 echo $menu;
38
39 }
40 write_html();