创建一个动态的PHP导航栏

时间:2015-05-19 00:07:38

标签: php

我正在尝试创建一个动态的PHP导航栏,我使用一个简单的模板引擎。 我能够创建动态导航,但是当我尝试创建下拉菜单时遇到了问题! 问题是每个主要项目都有很多子项目,但是当我运行我的脚本时,每个主要项目获得其他主要项目的相同子项目..

就像这样

main item 1 have sub item 1
main item 1 have sub item 2
main item 2 have sun item 3

当我运行我的脚本时,我得到了

main item 1  | main item 2  | main item 3  | 
sun item 1   | sun item 1   | sun item 1   | 
sun item 2   | sun item 2   | sun item 2   | 
sun item 3   | sun item 3   | sun item 3   | 

我需要它像这样

main item 1  | main item 2  | main item 3 | 
sun item 1   | sun item 2   | sun item 3  | 

我的代码!

$site_page_request = mysql_query("select * from pages where parent_id_sec='' order by navigation_order ASC");

$page_title = "page_title_lang_2";
$query_string = "query_string_lang_2";


while ($main_object = mysql_fetch_array($site_page_request)) {

    $links[] = array('link-name' = > $main_object[$page_title], 'link-link' = > "$site_link/".$main_object[$query_string].
        "/");

    $site_page_request2 = mysql_query("select * from pages where parent_id_sec='$main_object[id_sec]' order by navigation_order ASC");

    while ($main_object2 = mysql_fetch_array($site_page_request2)) {

        $links2[] = array('link-name2' = > $main_object2[$page_title], 'link-link2' = > "$site_link/".$main_object[$query_string].
            "/".$main_object2[$query_string].
            "/");
    }

}

foreach($links as $links) {

    $row = new Template("style/template/navigation-row.tpl");

    foreach($links as $key = > $value) {
        $row - > set($key, $value);
    }
    $navigationTemplates[] = $row;
}

$navigationContents = Template::merge($navigationTemplates);
$navigationList = new Template("style/template/navigation.tpl");
$navigationList - > set("row", $navigationContents);

$layout - > set("navigation", "$navigationContents");
$layout - > set("navigation", $navigationList - > output());

foreach($links2 as $links2) {

    $row2 = new Template("style/template/navigation-dropdown-row.tpl");

    foreach($links2 as $key = > $value) {
        $row2 - > set($key, $value);
    }
    $navigationTemplates2[] = $row2;
}

$navigationTemplates2 = Template::merge($navigationTemplates2);
$navigationList2 = new Template("style/template/navigation-dropdown.tpl");
$navigationList2 - > set("row2", $navigationTemplates2);
$layout - > set("navigation2", "$navigationTemplates2");
$layout - > set("navigation2", $navigationList2 - > output());

任何人都知道我应该怎么做!

谢谢!

0 个答案:

没有答案