title: Grouping Data using
body: <p>i am drawing a blank on this one and need some help. I have a database with metrics and I am trying to create a line chart. It involves grouping, or  merging, the records based on the ID of the metric so I can then loop over and then do a sub loop on the values to generate the XML to produce the chart using PHP.</p>
  
  <p>For example my recordset:</p>
  
  <pre><code>MetricID, Metric Name, Quarter,  Year, Value
  
  1   Total Calls 1   2011-01-01  22403.00
  
  1   Total Calls 2   2011-01-01  22366.00
  
  1   Total Calls 3   2011-01-01  34456.00
  
  1   Total Calls 4   2011-01-01  36456.00
  
  1   Total Calls 1   2012-01-01  38456.00
  
  1   Total Calls 2   2012-01-01  33256.00
  
  1   Total Calls 3   2012-01-01  35456.00
  
  1   Total Calls 4   2012-01-01  30456.00
  
  2   Total Referrals 1   2011-01-01  9668.00
  
  2   Total Referrals 2   2011-01-01  9154.00
  
  2   Total Referrals 3   2011-01-01  10445.00,
  
  2   Total Referrals 4   2011-01-01  12445.00
  
  2   Total Referrals 1   2012-01-01  12845.00
  
  2   Total Referrals 2   2012-01-01  10145.00
  
  2   Total Referrals 3   2012-01-01  10445.00
  
  2   Total Referrals 4   2012-01-01  12445.00
  </code></pre>
  
  <p>I need to loop over first the Total Calls to do a sub loop for the values, then loop over the Total Referrals, doing a sub loop of its values. Since the list is variable, I never know how many distince metric IDs I might get, 1 to 4.</p>
  
  <p>Thanks!</p>