Home > Backend Development > PHP Tutorial > 关于无限分类 循环DIV格式

关于无限分类 循环DIV格式

WBOY
Release: 2016-06-23 14:03:41
Original
812 people have browsed it



测试数据

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] =>         ))
Copy after login


需要转化的函数
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<count($class_arr);$i++){	         if($i % 2==1){             	$bgcolors="bgcolor=#e9f5fe";             	             }else{             	$bgcolors="bgcolor=#ffffff";             }             		if($class_arr[$i]['ppid']==$id){		echo "<tr ".$bgcolors." onmouseout=\"this.style.backgroundColor=''\" onmouseover=\"this.style.backgroundColor='#DEF1F1'\">\n";		echo "<td height=\"28\" align=\"center\" valign=\"middle\" >	                <input type=\"checkbox\" name=\"checkbox[]\" value='".$class_arr[$i]['id']."' /></td>";		echo "<td height=\"28\" class=\"font\"><div align=\"center\">".$class_arr[$i]['m_sort']."</div></td>\n";		echo "<td height=\"28\" class=\"font\">".$n."|--<a href=\"?action=edit&id=".$class_arr[$i]['id']."\">".$class_arr[$i]['m_title'].$m."</a></td>\n";		echo "<td height=\"28\" class=\"font\"></td>";		echo "<td height=\"28\" class=\"font\">".$class_arr[$i]['m_flag']."</td>";		echo "<td height=\"28\" class=\"font\"><div align=\"center\"><a href=\"sys_menu_add.php?action=edit&id=".$class_arr[$i]['id']."\">修改</a>";		echo " <a href=\"?action=del&id=".$class_arr[$i]['id']."\">删除</a>";		echo "</div></td>\n";		echo "</tr>\n";					dafenglei_arr($m+1,$class_arr[$i]['id']);		}			}	}
Copy after login


调用方式

dafenglei_arr(0,0);

显示的结果是




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

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


<ul id="files"><li id="m33"><a href="javascript:void(0);" >网站管理</a><ul><li><a href="/news-p11-pp33-ppp140" ><span class="">排序管理</span></a></li><li><a href="/news-p11-pp33-ppp141" ><span class="">登陆日志</span></a></li>	<li id="m33"><a href="javascript:void(0);" >系统信息</a>	<ul><li><a href="/news-p11-pp33-ppp140" ><span class="">系统分类</span></a></li></ul>	</li></ul></li><li id="m34"><a href="javascript:void(0);" >友情链接</a><ul><li><a href="/news-p11-pp34-ppp145" ><span class="">文字链接</span></a></li></ul></li></ul>
Copy after login



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




回复讨论(解决方案)

echo '<ul>';dafenglei_arr(1, 0);echo '</ul>';function dafenglei_arr($m,$id){    global $class_arr;    global $ppid;    if($id=="") $id=0;    for($i=0;$i<count($class_arr);$i++){      if($class_arr[$i]['ppid']==$id){        echo "<li>";        echo "<input type=\"checkbox\" name=\"checkbox[]\" value='".$class_arr[$i]['id']."' />";        echo $class_arr[$i]['m_sort'];        echo "|--<a href=\"?action=edit&id=".$class_arr[$i]['id']."\">".$class_arr[$i]['m_title'].$m.'</a>';        echo "<a href=\"sys_menu_add.php?action=edit&id=".$class_arr[$i]['id']."\">修改</a>";        echo " <a href=\"?action=del&id=".$class_arr[$i]['id']."\">删除</a>";        echo "\n<ul>";               dafenglei_arr($m+1,$class_arr[$i]['id']);        echo "</ul></li>\n";       }             }     }
Copy after login

echo '<ul id="files">';left_arr(1, 0);echo '</ul>';function left_arr($m,$id){    global $class_arr;    global $ppid;    if($id=="") $id=0;    for($i=0;$i<count($class_arr);$i++){      if($class_arr[$i]['ppid']==$id){        echo "<li>";        echo "<a href=\"javascript:void(0);\" >".$class_arr[$i]['m_title'].$m.'</a>';        echo "\n<ul>";               left_arr($m+1,$class_arr[$i]['id']);        echo "</ul></li>\n";       }              }      }
Copy after login



还差一点 谢谢..

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

<ul id="files"><li><a href="javascript:void(0);" >网站管理1</a><ul><li><a href="javascript:void(0);" >排序管理2</a><ul></ul></li><li><a href="javascript:void(0);" >登陆日志2</a><ul></ul></li><li><a href="javascript:void(0);" >系统信息2</a><ul><li><a href="###" >系统分类3</a><ul></ul></li></ul></li></ul></li><li><a href="javascript:void(0);" >关于我们1</a><ul></ul></li><li><a href="javascript:void(0);" >新闻中心1</a><ul></ul></li><li><a href="javascript:void(0);" >友情链接1</a><ul><li><a href="javascript:void(0);" >文字链接2</a><ul></ul></li></ul></li></ul>
Copy after login


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

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

差不多久是这种形式

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

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

     吗?

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

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

    呵呵  那能给下具体代码?  

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template