This article mainly introduces the PHP mysql function of obtaining the drop-down tree from the database, and analyzes the implementation skills of PHP mysql database query and select drop-down box output query results in the form of examples. Friends in need can refer to the following
The example of this article describes how PHP mysql implements the function of obtaining a drop-down tree from the database. Share it with everyone for your reference, the details are as follows:
<?php include "config.php"; include "MySQL.php"; $db = new Mysql('test'); //几个简单的类,不用列出来大家也看得懂。就是实例化一个数据库连接而已。 function RootMenu ($PID,$n){ global $arr,$db; $sql = "select * from menu where `PID` =$PID"; $result = $db->query($sql); while ($i=$db->fetch_array($result)){ $i["TITLE"] =str_repeat('--',$n).$i["TITLE"]; $arr[] =$i; RootMenu($i["ID"],($n+4)); } return $arr; } $arr = RootMenu(0,0); ?> <select id=""> <option value="0" selected="selected">请选择部门</option> <?php for ($i=0;$i<count($arr);$i++) { ?> <option value="<?php echo $arr[$i]["ID"] ?>"><?php echo $arr[$i]["TITLE"] ?></option> <?php }?> </select>
The above is the entire content of this article, I hope it will be helpful to everyone’s study .
Related recommendations:
PHP implementation of using mysqli to operate MySQLdatabase
How to use non-buffering mode to query database in PHP
PHP uses mysqli to operate MySQLdatabaseMethods
The above is the detailed content of PHP+mysql method to implement the drop-down tree function from the database. For more information, please follow other related articles on the PHP Chinese website!