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

墨辰丷
Release: 2023-03-28 09:04:01
Original
1663 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!