欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

关于无限分类 循环DIV格式

程序员文章站 2024-01-06 11:48:05
...
测试数据
Array(    [0] => Array        (            [id] => 10            [pid] => 0            [ppid] => 7            [m_title] => 系统分类            [m_flag] => 1            [m_type] => 0            [m_url] =>             [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 0            [m_time] => 0000-00-00 00:00:00        )    [1] => Array        (            [id] => 9            [pid] => 0            [ppid] => 6            [m_title] => 排序管理            [m_flag] => 0            [m_type] => 0            [m_url] =>             [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 0            [m_time] => 0000-00-00 00:00:00        )    [2] => Array        (            [id] => 8            [pid] => 0            [ppid] => 6            [m_title] => 登陆日志            [m_flag] => 0            [m_type] => 0            [m_url] =>             [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 0            [m_time] => 0000-00-00 00:00:00        )    [3] => Array        (            [id] => 7            [pid] => 0            [ppid] => 6            [m_title] => 系统信息            [m_flag] => 0            [m_type] => 0            [m_url] => 11            [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 10            [m_time] => 0000-00-00 00:00:00        )    [4] => Array        (            [id] => 6            [pid] => 0            [ppid] => 0            [m_title] => 网站管理            [m_flag] => 1            [m_type] => 4            [m_url] => 11            [m_lage] => 1            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 10            [m_time] => 0000-00-00 00:00:00        )    [5] => Array        (            [id] => 5            [pid] => 0            [ppid] => 2            [m_title] => 文字链接            [m_flag] => 0            [m_type] => 22            [m_url] =>             [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 10            [m_time] =>         )    [6] => Array        (            [id] => 4            [pid] => 0            [ppid] => 0            [m_title] => 关于我们            [m_flag] => 0            [m_type] => 0            [m_url] =>             [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 10            [m_time] =>         )    [7] => Array        (            [id] => 1            [pid] => 0            [ppid] => 0            [m_title] => 新闻中心            [m_flag] => 0            [m_type] => 0            [m_url] =>             [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 10            [m_time] =>         )    [8] => Array        (            [id] => 2            [pid] => 0            [ppid] => 0            [m_title] => 友情链接            [m_flag] => 0            [m_type] => 0            [m_url] =>             [m_lage] => 0            [m_seotitle] =>             [m_seokey] =>             [m_seodesc] =>             [m_sort] => 102            [m_time] =>         ))


需要转化的函数
function dafenglei_arr($m,$id){	global $class_arr;	global $ppid;	if($id=="") $id=0;	$n = str_pad('',$m,'-',STR_PAD_RIGHT);	$n = str_replace("-","      ",$n);	for($i=0;$i\n";		echo "	                
";		echo "
".$class_arr[$i]['m_sort']."
\n"; echo "".$n."|--".$class_arr[$i]['m_title'].$m." \n"; echo ""; echo "".$class_arr[$i]['m_flag'].""; echo "
修改"; echo " 删除"; echo "
\n"; echo "\n"; dafenglei_arr($m+1,$class_arr[$i]['id']); } } }


调用方式

dafenglei_arr(0,0);

显示的结果是




需要转换成div+css结构的无限树状分类

类似 http://www.bjshiyu.com/这个首页的产品分类的这个效果







总共发了三篇贴子...答对了 三篇帖子的分都给他160分....




回复讨论(解决方案)

echo '
    ';dafenglei_arr(1, 0);echo '
';function dafenglei_arr($m,$id){ global $class_arr; global $ppid; if($id=="") $id=0; for($i=0;$i"; echo ""; echo $class_arr[$i]['m_sort']; echo "|--".$class_arr[$i]['m_title'].$m.''; echo "修改"; echo " 删除"; echo "\n
    "; dafenglei_arr($m+1,$class_arr[$i]['id']); echo "
\n"; } } }

echo '
    ';left_arr(1, 0);echo '
';function left_arr($m,$id){ global $class_arr; global $ppid; if($id=="") $id=0; for($i=0;$i"; echo "".$class_arr[$i]['m_title'].$m.''; echo "\n
    "; left_arr($m+1,$class_arr[$i]['id']); echo "
\n"; } } }


还差一点 谢谢..

就是判断下有无子栏目
有子栏目的话 链接为javascript:void(0)
没有链接的话就是http://www.baidu.com


  • 网站管理1
  • 关于我们1
    • 新闻中心1
      • 友情链接1
        • 文字链接2


        就是说网站管理 下面有栏目(排序管理,登陆日志,系统信息) 系统信息下面有 系统分类

        网站管理链接为 javascript:void
        排序管理为www.baidu.com
        登陆日志为www.baidu.com
        系统信息为javascript:void
        系统分类 www.baidu.com

        差不多久是这种形式

        麻烦 老大 再给我修改下 谢谢...就差一点了

        你这是一遍扫描,不可能做到的。
        你没有发现生成的 html 中多了许多空的

          吗?

          既然 老大都说 不可能做到了..那我也就不折腾了...

          两边扫描才可以做到
          第一遍,结构化树状数组。这样就可以统计子节点数了
          第二遍,输出数组

          呵呵 那能给下具体代码?