Trying to figure out how to loop while grouping
<p>Here is the data I have:</p>

<pre><code>ID | Name | Family
 1 | John | Doe
 2 | Jane | Doe
 3 | John | Man
 4 | Jane | Blah
</code></pre>

<p>Basically what I am trying to do is group them by Family. I am getting the data inside a while statement and I just tried using array and array_push but that doesn't work at all. </p>

<p>Any ideas or suggestions on how to do this?</p>

<p>I am going to ouput this data for jquery for creating optgroups which would be grouped by Family. Currently here is what is happening: </p>

<pre><code>while ($orders_status = tep_db_fetch_array($orders_status_query)) {
    $status_id = $orders_status['orders_status_id'];
    $status_name = $orders_status['orders_status_name'];
    $status_group = $orders_status['orders_status_group'];
}
</code></pre>

<p>That's the basic code. I tried doing this to the above mentioned code:</p>

<pre><code>while ($orders_status = tep_db_fetch_array($orders_status_query)) {
    $status_id = $orders_status['orders_status_id'];
    $status_name = $orders_status['orders_status_name'];
    $status_group = $orders_status['orders_status_group'];

    echo 'if (currentOption.val() == "' . $status_id . '") {
              var optgroup = $("&lt;optgroup/&gt;");
              optgroup.attr("label", "' . $status_group . '");
              currentOption.wrapAll(optgroup);
          }
    ';
 }
</code></pre>

<p>What that did is basically created multiple Family of Doe. Instead I would like to somehow create only one Family of Doe and push Name and ID into it</p>
