Heim >Backend-Entwicklung >PHP-Tutorial >关于无限分类 循环DIV格式
测试数据
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<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']); } } }
<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>
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"; } } }
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"; } } }
<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>
麻烦 老大 再给我修改下 谢谢...就差一点了
你这是一遍扫描,不可能做到的。
你没有发现生成的 html 中多了许多空的
既然 老大都说 不可能做到了..那我也就不折腾了...
两边扫描才可以做到
第一遍,结构化树状数组。这样就可以统计子节点数了
第二遍,输出数组
呵呵 那能给下具体代码?