title: creating an option list with an optiongroup dynamicly using php mysql
body: <p>I'm trying to create a list of members in an HTML option list, but i want it to be divided according to the department of each member, because every member is working in aone department of the company .
  Here is the code i tried to use but was unsuccessful : </p>
  
  <pre><code>    &lt;?php
     echo'&lt;select size=1 name="Name List"&gt;'."\n";
     echo'&lt;option value="-1"&gt;--Name List--&lt;/option&gt;'."\n";
     $result1=mysql_query("select department from users");
  
     while($data1=mysql_fetch_array($result1)){
  
     echo'&lt;optgroup value="'.$data1[0].'"&gt;'.$data1['department'];
  
      $result=mysql_query('select username from users where department="'.$data1['department'].'" ');
  
     while($data=mysql_fetch_array($result)){
  
     echo'&lt;option value="'.$data[0].'"&gt;'.$data['username'];
     echo'&lt;/option&gt;'."\n";
     }
     echo'&lt;/optgroup&gt;'."\n";
     }
     echo'&lt;/select&gt;'."\n";
     mysql_close();
     ?&gt;
  </code></pre>