title: PHP select timediff with select query and group by user
body: <p>i have this SQL Query:</p>
  
  <pre><code>$sql="SELECT *, COUNT(assigned_to) AS my_groupcount from tickets where deleted = '' and DAY(datetime) = '".$_GET["d"]."' and MONTH(datetime) = '".$_GET["m"]."' and YEAR(datetime) = '".$_GET["Y"]."' group by assigned_to order by datetime ASC ";
      $rs=mysql_query($sql,$conn);
      while($result=mysql_fetch_array($rs))
      {
          //work out the total time taken
          $sql3="SELECT *,  TIMEDIFF( timeend, timestart ) AS support_time_used FROM ticket_updates WHERE ticket_seq = '".$result["ticketnumber"]."' ";
          $rs3=mysql_query($sql3,$conn) or die (mysql_error());
          $totaltime = 0;
          while($result3=mysql_fetch_array($rs3))
          {
              $totaltime = $totaltime+substr($result3["support_time_used"],0,2)*60+substr($result3["support_time_used"],3,2);
          }   
          $hours=intval($totaltime / 60);
          $minutes=$totaltime -($hours * 60);
          $total_ticket_time = $hours.'h '.$minutes.'m';
  
          echo $result["assigned_to"].' ('.$result["my_groupcount"].') - Time: '.$total_ticket_time.'&lt;br&gt;';
      }
  </code></pre>
  
  <p>so its selecting all the rows from the tickets table and grouping by the asigned_to column.</p>
  
  <p>it then works out the time used for each user from the <code>ticket_updates</code> table.</p>
  
  <p>the <code>ticket_updates.ticket_seq</code> column links to the <code>tickets.ticketnumber</code> column and there may be just one or multiple rows in the ticket_updates table for 1 row in the tickets table so it adds all the differences up in the <code>ticket_updates</code> table.</p>
  
  <p>im trying to list the assigned_to (one each) from the tickets table and put next to each one how much time they have used but its only selecting it form one ticket.</p>
  
  <p>how can i make it select from all the tickets?</p>