无限极分类
Posted 李先森博客
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无限极分类相关的知识,希望对你有一定的参考价值。
<?php
// header("Content-type: text/html; charset=utf-8");
header("Content-type: text/html; charset=gb2312");
$link = mysqli_connect("192.168.1.181","root","123456","teacher","3306");
$sql ="select * from user";
$row = mysqli_query($link,$sql);
while($arr = mysqli_fetch_assoc($row)){
$data[] = $arr;
}
$data1 = fun($data,$par_id=0,$leve=0);
function fun($data,$par_id=0,$leve=0)
{
static $list = array();
foreach ($data as $key => $v) {
if ($v[‘pid‘]==$par_id) {
$v[‘leve‘] =$leve;
$list[] = $v;
fun($data,$v[‘id‘],$leve+1);
}
}
return $list;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Document</title>
</head>
<body>
<select name="" id="">
<?php foreach ($data1 as $key => $v) { ?>
<option value="<?php echo $v[‘id‘]?>"><?php echo str_repeat(‘ ‘,$v[‘leve‘]).$v[‘name‘]?></option>
<?php } ?>
</select>
</body>
</html>
以上是关于无限极分类的主要内容,如果未能解决你的问题,请参考以下文章