title: Populate HTML/PHP Dropdown Based on First Dropdown Selection
body: <p>I have 1 Drop Down Which Is Used For Category (Food, Drink etc.)</p>
  <p>In my MySQL Table (t_menu_category) I Have:</p>
  <pre><code>+----+---------------+-------------------+----------------------+
  | ID | category_name | sub_category_name | category_description |
  +----+---------------+-------------------+----------------------+
  |  1 | Food          | Curries           | Spicy Curries        |
  |  2 | Food          | Meat              | Lamb, Pork, Chicken  |
  |  3 | Drinks        | Alcohol           | Fine Tasting Lager   |
  |  4 | Desserts      | Cakes             | Chocolate Cake       |
  +----+---------------+-------------------+----------------------+
  </code></pre>
  <p>I have got the first dropdown showing the values of &quot;category_name&quot; but what I want is when I select food I want the second dropdown box to update and just show the values of &quot;sub_category_name&quot; where the first selection e.g. &quot;Food&quot; equals &quot;Food&quot; in the database.</p>
  <p>So if I selected &quot;Food&quot; in the first dropdown box, the second dropdown box will only show &quot;Curries&quot; &amp; &quot;Meat&quot;.</p>
  <p>HTML:</p>
  <pre><code>&lt;form method=&quot;post&quot; action=&quot;&lt;?php $_SERVER['PHP_SELF'] ?&gt;&quot;&gt; 
                    
      &lt;p&gt; 
          &lt;label for=&quot;item_name&quot;&gt;Item Name&lt;/label&gt;
          &lt;input id=&quot;item_name&quot; name=&quot;item_name&quot; required=&quot;required&quot; type=&quot;text&quot; placeholder=&quot;Item Name&quot; /&gt;
       &lt;/p&gt;
       &lt;p&gt;
          &lt;label for=&quot;item_description&quot;&gt;Item Description&lt;/label&gt;
          &lt;textarea rows=&quot;3&quot; cols=&quot;100%&quot; required=&quot;required&quot; name=&quot;item_description&quot;&gt;Item Description&lt;/textarea&gt;
      &lt;/p&gt;
      &lt;p&gt;
          &lt;label for=&quot;item_category&quot;&gt;Item Category&lt;/label&gt;
          &lt;select id=&quot;item_category&quot; name=&quot;item_category&quot; required=&quot;required&quot;&gt;
              &lt;option selected=&quot;selected&quot;&gt;-- Select Category --&lt;/option&gt;
              &lt;?php 
              $sql = mysql_query(&quot;SELECT category_name FROM t_menu_category&quot;);
              while ($row = mysql_fetch_array($sql)){
              ?&gt;
              
              &lt;option value=&quot;&lt;?php echo $row['category_name']; ?&gt;&quot;&gt;&lt;?php echo $row['category_name']; ?&gt;&lt;/option&gt;
  
              &lt;?php
              // close while loop 
              }
              ?&gt;
          &lt;/select&gt;
      &lt;/p&gt;
  
      &lt;p class=&quot;center&quot;&gt;&lt;input class=&quot;submit&quot; type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Add Menu Item&quot;/&gt;&lt;/p&gt;
  &lt;/form&gt;
  </code></pre>