1. 程式人生 > >全路徑無限分類下拉列表的實現

全路徑無限分類下拉列表的實現

rom fun rep 最終 [] 深度 color -- echo

最終效果圖:

技術分享圖片

技術分享圖片

代碼詳情:

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(‘
&nbsp;&nbsp;‘,$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);

全路徑無限分類下拉列表的實現