title: Make a Dynamic Drop Down Navigation system
body: <p>I am trying to create a Dropdown Menu on my site, Ive hit a brick wall and cannot think on how to do it.</p>
  
  <p>Basically i need to check 2-3 variables in a database and out put the correct data.</p>
  
  <p>I have at the moment it checking if its an External Link or Not, and if it contains a submenu, but i can't get it to output the correct information.</p>
  
  <p>Basically i want it to check if its a External or Non-External link, and if it has a submenu, if it has a submenu, to display the menu options underneath it. So say i have menu 1, 2 ,3, 4 and 2,4 has a submenu, i need them to list the other links under them. i have put in my database toplink_id (to represent which link this item should be under) sc_order (which will control the order the sublinks display in) also dropdown (which tells me if the menu has a submenu or not.)</p>
  
  <p>Here is the start of my code</p>
  
  <pre><code>$sql = "SELECT label, url, ext, dropdown FROM content_pages WHERE top_nav='1' AND active='1' ORDER by page_order ASC"; 
  $query = mysqli_query($dbc, $sql) or die (mysqli_error($dbc));
  
  $menuDisplay .= '&lt;div class="bg-2"&gt;&lt;div class="container_12"&gt;&lt;article class="grid_12"&gt;&lt;nav&gt;&lt;ul class="menu sf-js-enabled"&gt;';
  
  while ($row = mysqli_fetch_array($query)) { 
  
  $url = $row["url"];
  $nav_label = $row["label"];
  $drop_down ='&lt;ul&gt;&lt;li&gt;&lt;a href="../pages/' . $url . '"&gt;' . $nav_label . '&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;'; 
  
  
  if ($row["ext"] == 0 &amp;&amp; $row["dropdown"] == 1){
  
  $menuDisplay .= '&lt;li&gt;&lt;a href="../pages/' . $url . '"&gt;' . $nav_label . '&lt;/a&gt;'  . $drop_down . '&lt;/li&gt;';
  }
  
  elseif ($row["ext"] == 1 &amp;&amp; $row["dropdown"] == 1){
  
  $menuDisplay .= '&lt;li&gt;&lt;a href="../' . $url . '"&gt;' . $nav_label . '&lt;/a&gt;'  . $drop_down . '&lt;/li&gt;';
   }
   elseif ($row["ext"] == 0){
  
  $menuDisplay .= '&lt;li&gt;&lt;a href="../pages/' . $url . '"&gt;' . $nav_label . '&lt;/a&gt;&lt;/li&gt;';
  }
  
  elseif ($row["ext"] == 1)
  {
      $menuDisplay .= '&lt;li&gt;&lt;a href="../' . $url . '"&gt;' . $nav_label . '&lt;/a&gt;&lt;/li&gt;';
  }
  
  
  
  } 
  $menuDisplay .= '&lt;/ul&gt;&lt;/nav&gt;&lt;/article&gt;&lt;/div&gt;&lt;/div&gt;&lt;/header&gt;';   
  mysqli_free_result($query);
  </code></pre>