title: Ordering records that are timestamped
body: <p>I have a tricky one here.</p>
  
  <p>I have a number of results in a table, this table has id, market, date and points.</p>
  
  <p>I want to get all the records for a given month and then output all the points for each day, in order. </p>
  
  <p>I'm not sure of the best way to do this? Her are my options, well my ideas, I could set a loop that will execute for every day of the given month, this will run a query to find every record for that day and will do this for every day of the month, this will then be easy to order a format the records but i'm thinking its not a good idea to query the database that many times.</p>
  
  <p>The second idea i to query the database for all the records for that date, order them by the date. However i can see come problems here when outputting the information for each day, well it will be a long job then the first i think. </p>
  
  <p>Any ideas? anyone done something like this before and could lend a helping hand? Any advise would be more than welcome!</p>
  
  <p>Thanks.</p>
  
  <pre><code>while($row = mysql_fetch_array($getresults))
  {
      $day = FALSE;
  
      foreach ($row as $row)
      {
          $day_res = date("Y-m-d H:m:s", strtotime($row["date"]));
  
          if (!$day || $day != $day_res)
          {
              $day = $day_res;
              echo '&lt;h1&gt;'.$day.'&lt;/h1&gt;';
          }
  
          echo $row['date'] . " " . $row["id"] . ": " . $row["market"] . 
                      "/" . $row["points"] . "&lt;br/&gt;";
      }
   }
  </code></pre>
  
  <p>This is the output i get from it:</p>
  
  <pre><code>1970-01-01 00:01:00
  
  3 3: 3/3
  3 3: 3/3
  2012-01-13 09:01:06
  
  E E: E/E
  E E: E/E
  1970-01-01 00:01:00
  
  2 2: 2/2
  2 2: 2/2
  - -: -/-
  - -: -/-
  1970-01-01 00:01:00
  
  4 4: 4/4
  4 4: 4/4
  </code></pre>
  
  <p>and that more or less repeats for a while.</p>
  
  <p>Thanks again.</p>