0

私はphpでかなり新しいです!小さな cms のナビゲーション用のクラスを作成したいと考えています。それは 1 つのことを除いて正常に動作します: すべてのページとサブページが 1 回表示されるのではなく、2 回表示されます。

これは私がクラスを呼び出す方法です:

<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
4

3 に答える 3