title: How I can make drop down menu from my categories mysql table only show if parent_id is not 0
body: <p>So hey there as the title said I am looking for away to make my categories with subcategories. I been looking in stackoverflow for what I need but none has help me of the examples..</p>
  
  <p>Here is how my table look like
  <a href="https://i.stack.imgur.com/VIUB2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VIUB2.jpg" alt="enter image description here"></a>
  So I know what I want and what I need but I have no idea how I can do that possible</p>
  
  <ol>
  <li>I have to <code>SELECT * FROM categories ORDER by position ASC</code></li>
  <li>I have to check if <code>parent_id</code> is bigger then 0.</li>
  <li>I have to remove the <code>parent_id</code> from my navbar and show them only under the category name where it should be by <code>dropdown menu</code> .</li>
  </ol>
  
  <p>But I have no idea how I could do all of that ..</p>
  
  <p>Here is how I am selecting only my categories and display them</p>
  
  <pre><code>                  $catsq = mysqli_query($con,"SELECT * FROM categories ORDER by position ASC");
                      while($catinfo=mysqli_fetch_assoc($catsq)) {
                        echo '
                           &lt;li class="nav-item'.(isset($_GET["cat"]) &amp;&amp; $_GET["cat"]==$catinfo["id"] ? " active" : "").'"&gt;
                             &lt;a class="nav-link" href="./index.php?cat='.$catinfo["id"].'"&gt;'.$catinfo["name"].'&lt;/a&gt;
                           &lt;/li&gt;
                        ';
                      }
  </code></pre>
  
  <p>and it's look like this</p>
  
  <pre><code>&lt;ul class="nav navbar-nav"&gt;
      &lt;li class="nav-item"&gt;
      &lt;a class="nav-link" href="cat=1"&gt;TestCat&lt;/a&gt;
      &lt;/li&gt;
      &lt;li class="nav-item"&gt;
      &lt;a class="nav-link" href="cat=2"&gt;TestCat2&lt;/a&gt;
      &lt;/li&gt;
      &lt;li class="nav-item"&gt;
       &lt;a class="nav-link" href="cat=3"&gt;TestSub&lt;/a&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>but I want It to look like this</p>
  
  <pre><code>&lt;ul class="nav navbar-nav"&gt;
      &lt;li class=""&gt;&lt;a href="cat=1"&gt;TestCat&lt;/a&gt;&lt;/li&gt;
      &lt;li class="dropdown "&gt;
          //TestCat2 have to doing nothing always.
          &lt;a href="#" class="dropdown-toggle" data-toggle="dropdown"&gt;TestCat2&lt;/i&gt;&lt;/a&gt;
          &lt;ul class="dropdown-menu"&gt;
              &lt;li&gt;&lt;a class="nav-link" href="cat=3"&gt;TestSub&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>when the <code>parent_id</code> is more then 0..</p>
  
  <p>If anyone can help me with this would be great..</p>
  
  <p>Thanks to everybody.</p>