title: How to add optgroup to dropdown loop?
body: <p>I have a loop that displays a list of variables in a dropdown box (based on the filtered category).  I'd like to add in option groups (using subcategories) from my table.  How can I add this to part of my loop?  </p>
  
  <p>In the example below, the category is "countries" and subcategory is "continents".  I'd like the countries to be listed within the appropriate continent optgroup.</p>
  
  <pre><code>&lt;select id="country"&gt;
    &lt;option value=""&gt;Select&lt;/option&gt;
  
   &lt;?php
       $c_sth = $c_dbh-&gt;query ("SELECT category, subcategory, display, value
                                FROM constants WHERE category='Countries'
                                ORDER BY display");
       while ($row = $c_sth-&gt;fetch ()) {
         echo '&lt;option value="'.$row['value'].'"&gt;'.$row['display'].&lt;/option&gt;'."\n";
       }
   ?&gt;
  
  &lt;/select&gt;
  </code></pre>