title: Display sub category of specific category link hovered in navigation menu toggle drop down sub menu in php
body: <p>I want to display only the sub category that is belongs to a specific category clicked from the navigation menu.But this code dispalys all the sub categories on hover</p>
  
  <p><strong>PHP code :</strong></p>
  
  <pre><code>  $mysqli = new mysqli("localhost", "root", "", "carz");
  
      /* check connection */
      if ($mysqli-&gt;connect_errno) {
          printf("Connect failed: %s\n", $mysqli-&gt;connect_error);
          exit();
      }
      $query = "SELECT * FROM categories";
      $result = $mysqli-&gt;query($query);
      //echo $row["cname"];
      //printf ("%s (%s)\n", $row["cid"], $row["cname"]);
      echo "&lt;ul class='dropdown'&gt;";
      while ($row = $result-&gt;fetch_array(MYSQLI_ASSOC)) {
       echo '&lt;li &gt;&lt;a href="#" class="dropbtn"&gt;' . $row["cname"] .'&lt;/a&gt;';
           echo '&lt;ul class="dropdown-content"&gt;';
            $query2 = "SELECT * FROM categories_sub WHERE cid=".$row["cid"]."";
            $result2 = $mysqli-&gt;query($query2);
           // loop through the sub cats
           while ($row2 = $result2-&gt;fetch_array(MYSQLI_ASSOC)) {
               // if there were sub sub cats etc you just keep this code going deeper
               echo '&lt;li&gt;&lt;a href="#"&gt;'.$row2["csname"].'&lt;/a&gt;&lt;/li&gt;';
           } // end sub cats loop
           echo '&lt;/ul&gt;';
        // end check for results
       echo "&lt;/li&gt;";  
      }
  
  /* free result set */
  echo "&lt;/ul&gt;";
  $result-&gt;free();
  /* close connection */
  $mysqli-&gt;close();
  </code></pre>