db_query group by to array I have the following query:

$query = "SELECT *
      FROM mytable
      {$typeClause}
      HAVING distance &lt;= {$radius}
      ORDER BY distance ASC"
      GROUP BY type;

    $result = db_query($query);
    $points = array();

    while(($point = $result-&gt;fetchAssoc()) != null){
    }


In my db there is field 'type' which is a number 
How can I get all records as an array without using the while statement above (something like fetchByGroup):

array(
        '1' =&gt; array( [all records of type=1] ),
        '2' =&gt; array( [all records of type=2] ),
        ......................................
    );
You cannot do this using native Drupal 7 functionality. You need to do that grouping in PHP. You should be using a foreach, not a while loop :)


  The most common case is to iterate over the result set with a
  foreach() loop.


Source: https://drupal.org/node/1251174