(a) Please read the general guidelines in the Newbie's forum before posting such a large amount of code again.
(b) Your problem is that you're trying to print the resource (which is why it gives a resource #), instead of fetching the sum out of the resource the way you as for everything else.
The problem (and the bit that needed posting) is here:
$HoursSum= "SELECT sum(Hours) FROM transactions WHERE AgencyID=$id";
echo $HoursSum;
$TotalHours= mysql_query($HoursSum);
echo $TotalHours;
should be
$HoursSum= "SELECT sum(Hours) FROM transactions WHERE AgencyID=$id";
echo $HoursSum;
$result=mysql_query($HoursSum);
$TotalHours= mysql_result($result,0);
echo $TotalHours;
Oh, and you really don't need to keep selecting the same database over and over again with ever query.