title: Building a time interval array of values using php
body: <p>I am attempting to build a Latency Area Chart using php and json to take datapoints I have in a MySQL database, and average them into 5 minute intervals.  I am wondering if something like this is even possible.</p>
  
  <p>Current Code:</p>
  
  <pre><code>mysql_select_db($mysql_db);
  $query = ("select date, (delta_msec * .001) from www where agent_id in (45517,45655,42189,38583,45872,38678,38289,39074,38069,42096,37987,45182,38974,44956,38630,38297,38571,39181,39063,41992,38293,37978) and date &gt;='" . date("Y-m-d H:i:s", strtotime("30 minutes ago")) . "' and date &lt;= '" . date("Y-m-d H:i:s", strtotime("now"))  . "' order by date asc");
  $result = mysql_query($query) or die($query. "&lt;br/&gt;&lt;br/&gt;" .mysql_error());
  while ($row = mysql_fetch_array($result)){
      $www[$q] = array("label" =&gt; $row[0], "value" =&gt; $row[1]);
      $q++;
  }
  </code></pre>
  
  <p>When using</p>
  
  <pre><code>print_r ($www);
  </code></pre>
  
  <p>I am able to see the following (correct) Multi-dimentional array:</p>
  
  <pre><code>Array
  (
  [0] =&gt; Array
      (
          [label] =&gt; 2012-12-14 12:47:17
          [value] =&gt; 0.618
      )
  
  [1] =&gt; Array
      (
          [label] =&gt; 2012-12-14 12:47:17
          [value] =&gt; 0.890
      )
  
  [2] =&gt; Array
      (
          [label] =&gt; 2012-12-14 12:47:22
          [value] =&gt; 1.908
      )
  
  [3] =&gt; Array
      (
          [label] =&gt; 2012-12-14 12:47:37
          [value] =&gt; 2.912
      )
  
  [4] =&gt; Array
      (
          [label] =&gt; 2012-12-14 12:48:18
          [value] =&gt; 1.275
      )
  
  [5] =&gt; Array
      (
          [label] =&gt; 2012-12-14 12:48:25
          [value] =&gt; 0.449
      )
  
  [6] =&gt; Array
      (
          [label] =&gt; 2012-12-14 12:48:30
          [value] =&gt; 7.831
      )
  )
  </code></pre>
  
  <p>The Array is MUCH larger than this, but I wanted to give a snippet of how it looks.</p>
  
  <p>With this information I can convert this into JSON and FusionCharts will read all the values perfectly.  However, it's really just a reformatted "scatterplot" graph which doesn't read well.  I would like to be able to create another array from this Array so that I can basically make 5 minute buckets and average all of the values and do this for the past 4 hours.  </p>
  
  <p>I have only begun learning PHP, MySQL and fusioncharts (all at once) for about 2-3 weeks now and this is far beyond what I have learned.  Would anyone be able to assist in creating an array like this? (or any other method?)  Or would I only be able to do this by reformatting my SQL query to pull the data averaged already, and then make this call again for smaller versions of the graph?</p>