我是php新手!我想为我的小 cms 的导航创建一个类。它可以正常工作,除了一件事:所有页面和子页面都不是应该显示一次而是显示两次..你能帮帮我吗!
这就是我所说的类:
<div id="nav">
<ul class="navigation">
<?php
$navigation_object = new Navigation();
$navigation_object->navigation();
?>
</ul>
</div>
这是课程:
class Navigation {
var $nav_set;
var $nav;
var $selected_nav;
var $page_set;
var $page;
var $selected_page;
public $output = NULL;
public function navigation() {
//_____________________________ NAV _____________________________
// 3. Performing database query for table NAV
$get_all_nav_object2 = new Get_all_nav();
$this->nav_set = $get_all_nav_object2->get_all_nav_function();
// 4. Using returned data for table NAV (in variable $nav_set)
while ($this->nav = mysql_fetch_array($this->nav_set)) {
$output = "<li";
if ($this->nav["id"] == $this->selected_nav['id']) {
$output .= " class=\"selected\"";
}
$output .= "><a href=\"content.php?nav_id=" . urlencode($this->nav["id"]) .
"\">{$this->nav["nav_name"]}</a></li>";
// _____________________________ PAGES _______________________________________
// 3b. Performing database query for table PAGES (sub-navigation)
$get_pages_object1 = new Get_pages_for_nav();
$this->page_set = $get_pages_object1->get_pages_for_nav_function($this->nav["id"]);
$output .= "<ul class=\"sub_navigation\">";
// 4b. Using returned data for table PAGES (in variable $page_set)
while ($this->page = mysql_fetch_array($this->page_set)) {
$output .= "<li";
if ($this->page["id"] == $this->selected_page['id']) {
$output .= " class=\"selected\"";
}
$output .= "><a href=\"content.php?page_id=" . urlencode($this->page["id"]) .
"\">{$this->page["page_name"]}</a></li>";
}
$output .= "</ul>"; //closing ul for sub_navigation
echo $output;
} // END of the previous while: while ($nav = mysql_fetch_array($nav_set))
} // end function
} // end class