title: Iterating dropdown list with optgroup in PHP
body: <p>I am developing an application in CodeIgniter One of my dropdown consists of 86 options which should be generated dynamically and I have decided to make them in <code>&lt;optgroup&gt;</code> as shown in the below screenshot.</p>
  
  <p><img src="https://i.stack.imgur.com/iGoXb.png" alt="enter image description here"></p>
  
  <p>I have stored all these options in mysql database. Now my question is I want to iterate these options using <code>foreach()</code> loop so that the Group labels should display for each group. (In the screenshot Education, Hospitality). I don't like the way of hard coding these 86 options. Can someone help me in solving this problem.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is my MySQL Table. I have mentioned Education list instead of occupation list. But the table structure is same.</p>
  
  <pre><code>mysql&gt; select * from wededucationlist limit 10;
        +-------+---------------------------+
        | eduid | education                 |
        +-------+---------------------------+
        |     1 | Aeronautical Engineering  |
        |     2 | B Arch                    |
        |     3 | BCA                       |
        |     4 | BE/B-Tech                 |
        |     5 | B Plan                    |
        |     6 | BSc IT / Computer Science |
        |     7 | Other Bachelor Degree     |
        |     8 | M Arch                    |
        |     9 | MCA                       |
        |    10 | ME                        |
        +-------+---------------------------+
        10 rows in set (0.00 sec)
  </code></pre>