Home  >  Article  >  Backend Development  >  PHP+mysql method to implement the drop-down tree function from the database

PHP+mysql method to implement the drop-down tree function from the database

墨辰丷
墨辰丷Original
2018-05-26 16:41:331664browse

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(&#39;test&#39;); //几个简单的类,不用列出来大家也看得懂。就是实例化一个数据库连接而已。
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(&#39;--&#39;,$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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn