title: MySQL Select Group By and Order By
body: <p>Here is the SQL Statement that I am using..</p>
  
  <pre><code>$sql = "SELECT surname, forename, count(*) FROM people WHERE user_id='$user_id'
          GROUP BY surname ORDER BY time";
  
  $result = mysql_query($sql);
  $count=mysql_num_rows($result);
  
  if($count &gt; 0){
  while($row = mysql_fetch_array($result)) {
  $i = $i +1;
  $person[$i] = $row['surname'].'&amp;&amp;'.$row['forename'];
  } 
  </code></pre>
  
  <p>What I would like to get is all the entries from the people database relative to user_id grouped by surname and ordered by the time that they were entered in to the database. e.g.</p>
  
  <pre><code>12:00  Smith  James
  13:00  Smith  Linda
  14:00  Smith  Sam
  
  12:30  OtherSurname  Lydia
  13:30  OtherSurname  Harry
  14:30  OtherSurname  Phil
  </code></pre>
  
  <p>The problem at the moment is that I only get one result for each surname.
  How can I use the SELECT statement with GROUP BY and ORDER BY to get all of the entries? thank you.</p>