while(list($ID, $Client, $Exec, $mth, $yr, $revenue) = mssql_fetch_array($result)){
if ($ID == $lastID){ // add to the last ID revenue array
$list[$ID][Revenue]["$mth-$yr"]=$revenue;
}
else{
$list[$ID] = array("Client" => "$Client",
"Exec" => "$Exec",
"Revenue" => array("$mth-$yr"=>"$revenue"));
}
$lastID = $ID;
}
I'd do something similar, I guess, but I would make the revenue entry an array itself (keyed by month):
$daterange = [];
while(list($ID, $Client, $Exec, $mth, $yr, $revenue) = mssql_fetch_array($result))
{
$daterange[] = "$yr-$mth"; // Note order for sorting
if(!isset($list[$ID]))
{
$list[$ID] = ['Client' => $Client, 'Exec' => $Exec, 'Revenue' => []];
}
$list[$ID]['Revenue']["$mth-$yr"] = $revenue;
}
sort($daterange);
$first_date = $daterange[0];
$last_date = $daterange[count($daterange)-1];
Where the stuff involving [font]$daterange[/font] is only there if you don't have a better way of determining the range that the date columns are supposed to span. If you've got that some other way, then said stuff isn't needed.
Then each record in [font=monospace]$list[/font] will contain all the details for a given row of the output. Going through each of those rows, any missing dates in the Revenue array means a blank for that date in the output row.