i have this SQL Query:
$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.'<br>';
}
so its selecting all the rows from the tickets table and grouping by the asigned_to column.
it then works out the time used for each user from the ticket_updates
table.
the ticket_updates.ticket_seq
column links to the tickets.ticketnumber
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 ticket_updates
table.
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.
how can i make it select from all the tickets?