title: MySQL: group on timestamp
body: <p>I have a messages table like this:</p>
  
  <p><img src="https://i.stack.imgur.com/IDXbk.jpg" alt="enter image description here"></p>
  
  <p>And I want to group the messages with the same timestamp into a secondary table. The expected output is something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/hk1pk.jpg" alt="enter image description here"></p>
  
  <p>I'm using the following script, but for some reason it isn't working:</p>
  
  <pre><code>&lt;?php 
  $message = mysql_query("select * from message group by member_id");
  while($row = mysql_fetch_array($message)) {
      @mysql_query("insert into message2 
                   values
                  ('$row[time_recorded]','$row[member_id]',
                   '$row[message]')");
  }
  </code></pre>