title: Lost behind the logic of making a stats graphics from a mysql log
body: <p>Thanks for reading.
  This is not a coding question as much as it is a logic one. But if my current logic is wrong, some coding help would be appreciated.</p>
  
  <p>I have made a table on my database which is a log of everything that happens on my site.
  When a user registers, it's saved. When he logs, again. And so on. Each action is represented by a number.</p>
  
  <p>The data looks like this</p>
  
  <pre><code>----------------------------
  | id | action | timestamp  | 
  ----------------------------
  | 1  | 1      | 1299132900 |
  | 2  | 2      | 1346876672 |
  | 3  | 14     | 1351983948 |
  | 4  | 1      | 1359063373 |
  ----------------------------
  </code></pre>
  
  <p>ID and action are of type INT(11) and timestamp is TIMESTAMP</p>
  
  <p>I'm using a query to retrieve all records from the last 30 days.</p>
  
  <pre><code>SELECT id, action, timestamp FROM log WHERE timestamp &gt;= DATE_SUB( CURDATE(),INTERVAL 30 DAY)
  </code></pre>
  
  <p>It works, and gives me all the correct values.</p>
  
  <p>I need to arrange this data to make a graphic in flot.</p>
  
  <p>As I see it, there are 2 steps:</p>
  
  <ol>
  <li>Group the results by action number.</li>
  <li>Then, inside each group, separate values by date, so the X axis of the graphic is date and Y axis is count.</li>
  <li>With those arrays I could make different javascript data arrys to pass to flot.</li>
  </ol>
  
  <p>Am I on the right track?
  Should there be several mysql queries, or a GROUP BY clause?
  I'm kind of lost here and would appreciate any help.</p>