您的位置:首页 > 其它

全路径无限分类下拉列表的实现

2018-09-19 17:44 387 查看

最终效果图:

代码详情:

include('db.inc.php');
function likecate($path=''){
sql = "select id,catename,path,concat(path,',',id) as fullpath from likecate order by fullpath asc";
$res = mysql_query($sql);
$result = array();
while($row = mysql_fetch_assoc($res)){
$deep = count(explode(',',trim($row['fullpath'],','))); //取数组的深度,去除逗号
$row['catename'] = str_repeat('  ',$deep).'|--'.$row['catename'];
$result[] = $row;
}
return $result;
}
$res = likecate();
echo "<select name= cate>";
foreach ($res as $key => $value) {
echo "<option> {$value['catename']}</option>";
}
echo "</select>";
print_r($res);

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: