Home >Backend Development >PHP Tutorial >树状循环输出,好几天了也没做好,请大神帮帮参考下

树状循环输出,好几天了也没做好,请大神帮帮参考下

WBOY
WBOYOriginal
2016-06-20 12:30:22779browse

数据库  

怎么输出为这样的

<select><option value="8">111111</option><option value="13">*121212</option><option value="14">*32323232</option><option value="9">22222222</option><option value="10">*333333</option><option value="11">**44444444</option><option value="12">***555555</option><option value="17">***werwerwer</option><option value="19">**6565656</option><option value="15">*23232323</option><option value="16">**324234234</option></select>


sonclass 是包含的子类id    怎么能树状循环出html这样的效果? 我只会输出一层  没办法向这样有子分类就一直循环输出出来


回复讨论(解决方案)

你这里不需要子id,有父id就行啦,你根据classid查询子id就行了

有父id,featherclass=classid,就能到到classid的下级

你这是想做什么??

有父id,featherclass=classid,就能到到classid的下级


可以写出具体点的吗 感谢!!

$class  =  $this->tclass->get_all_class($this->tbname);        $json_class = Array();			        $json_class2 = array();        foreach ($class as $key=>$value) {						  if($class[$key]['sonclass']) //如果有子分类            {                $json_class[$key]['id'] = $value['classid'];                $json_class[$key]['text'] = $value['classname'];                $son_arr = $this->tclass->get_son_class($value['sonclass'],$this->tbname);                foreach ($son_arr as $k=>$v) {                   $json_class1[$k]['id'] = $v['classid'];                   $json_class1[$k]['text'] = $v['classname'];				   				                   }               $json_class[$key]['children'] = $json_class1;            }        }


我这样只能得出父和一层子  怎么能循环得出子类?

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