我正在尝试将动态递归导航列表菜单添加到我正在处理的网站.
场景是菜单有两个与parentid(preid)相关的关卡.
我的问题是我可以正确显示第一级列表,但是我无法正确显示第二级.我不确定在哪里添加第二级的UL和/ UL标签.
这就是我所追求的
- Item 1
- item 2
- item 3
- sub item 1
- sub item 2
- Item 4
- item 5
- sub item 1
- sub item 2
- item 6
这实际上是我得到以下代码:
- item 1
- item 2
- sub item 1
- sub item 2
- Sports Injuries
下面是我用来创建菜单的类文件:
class Dynamic_Menu
{
function getConfig()
{
$this->DB_SERVER = 'localhost';
$this->DB_USER = '***';
$this->DB_PASS = '***';
$this->DB_NAME = '***';
}
function __construct()
{
$this->getConfig();
$Conn = mysql_connect($this->DB_SERVER, $this->DB_USER, $this->DB_PASS);
if (!$Conn)
die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
$DB_select = mysql_select_db($this->DB_NAME, $Conn);
if (!$DB_select)
die("Error: ".mysql_errno($Conn).":- ".mysql_error($Conn));
}
function select_row($sql)
{
//echo $sql . "
";
if ($sql!="")
{
$result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
if ($result)
{
while($row = mysql_fetch_array($result))
$data[] = $row;
}
return $data;
}
}
function recordCount($sql)
{
if ($sql!="")
{
$result = mysql_query($sql) or die("Error: ".mysql_errno().":- ".mysql_error());
if ($result)
{
$cnt = mysql_num_rows($result);
return $cnt;
}
}
}
function getChild($id)
{
$menu = "";
$str = "";
$s = "SELECT * FROM vcms_sys_explorer WHERE preid = '$id' ";
$res = $this->select_row($s);
$menu .= '
- ';
for ($i=0;$i
{
$cnt_of_child = $this->recordCount("SELECT * FROM vcms_sys_explorer where preid = '".$res[$i][eid]."' ");
//if ($cnt_of_child > 0)
// $str = '';
//else
// $str = " (is sub menu item)";
$menu .= '
'. $res[$i][name].$str.'';$menu .= $this->getChild($res[$i][eid]);
}
$menu .= '
';return $menu;
}
function getMenu($parentid)
{
$menu = "";
$s = "SELECT * FROM vcms_sys_explorer WHERE preid = '$parentid' ";
$res = $this->select_row($s);
$menu .= '
- ';
for ($i=0;$i
{
$menu .= '
'.$res[$i][name].$this->getChild($res[$i][eid]).'';if ((count($res) - 1) > $i) {
}
}
$menu .= '
';return $menu;
}
}
我用以下方式调用菜单:
$menu = new Dynamic_Menu();
$menu->getMenu(1);
有人可以帮助并解释我需要放置2级UL和/ UL标签的位置.在过去的两天里,我一直在用这个打击我.
非常感谢任何帮助,谢谢……