我很难让这个菜单正常工作。
function writeMenu(){
echo "<div id='"menu'">" <ul id='"top-link'">";
m("top", "n"); echo "</ul></div>";
(抱歉,无法正确格式化)
function m($parent,$issub){
$parentQ = "select * from cdi_menu";//gets menu items from menu table
$parentResult = mysql_query($parentQ); //runs menu item query and obtains result
while ($link = mysql_fetch_assoc($parentResult)) {//for each line in the result do the folowing:
if($parent==$link['PARENT']){//if the next link belongs to this menu item
echo "'n <li><a href='"".$link['LINK']."'">".$link['DISPLAY']."</a></li>";
if($issub=="n" && $link['HASCHILD']=="y"){//if this menu item is a top menu item
echo "'n <li id='"sub-link'"><ul>";
m($link['ID'], $links, "y");
echo "'n </ul></li>";
}
}
}
}
echo writeMenu();
我想做的是把它放在可以隐藏"子链接"ID的地方(我会使用类,但javascript似乎不编辑类样式,只编辑ID)。子链接项目将在父项目上显示。
top
表示顶级元素,ID
表示数据库中的唯一id。
谢谢,如果让人困惑的话,很抱歉。
你的函数只有2个参数,但你在中用3个参数调用它
m($link['ID'], $links, "y");
$links是不必要的。
如果您修改查询使其看起来像这个会更好
$parentQ = "select * from cdi_menu WHERE parent='$parent'";
因此,您不需要第一个if语句,也不会为每个菜单/子菜单多次获取所有行。