Meltdown
05-26-2011, 03:34 PM
I have an array of dates ($dateMonthYearArr):
Array ( [0] => 04.04.2011 [1] => 04.05.2011 [2] => 04.06.2011 [3] => 04.07.2011 [4] => 04.08.2011 [5] => 04.09.2011 )
For each of the dates in the array, I want to run a query that returns the average a column:
foreach ($dateMonthYearArr as $csm_sum_for_date){
$i=0;
//Run query and calc occ average for each day
echo "Date - $csm_sum_for_date<br />";
$drillq = mysql_query("$csm_query statistic_date='$csm_sum_for_date' LIMIT 700" );// or die(mysql_error());
while($row_drillq = mysql_fetch_array( $drillq )) {
$i++;
$hnl_tme = $row_drillq['tlk_tme'] + $row_drillq['hld_tme'] + $row_drillq['acw_tme']; //correct!
$avl_tme_occ = $row_drillq['sum_avl_tme']/$row_drillq['cnt_ph_skll']; //correct!
$occ = $hnl_tme+$avl_tme_occ;
$csm_occ = $hnl_tme/$occ*100;//For csm averaging
$occ = $hnl_tme/$occ*100; //correct!
$occ = round("$occ", 0);
$stat_date = $row_drillq['statistic_date'];
$csm_occ_array[] = "$csm_occ";//For csm averaging
echo "$i - $csm_occ | $row_drillq[agent]<br />";
}//while
print_r ($csm_occ_array);
$csm_daily_occ_sum = array_sum($csm_occ_array);
$csm_daily_occ_sum_percent = $csm_daily_occ_sum/$i;
$csm_daily_occ_sum_percent = round("$csm_daily_occ_sum_percent", 0);
echo "<br /><b>$i - $csm_daily_occ_sum - $csm_daily_occ_sum_percent% </b><br /><br />";
}//foreach
The problem I have is that I'm not sure how to get the percentage and sum for EACH day individually. What I have compounds the averages and sum as it progresses (for example: if day 1 = 10 and day 2 = 5, it shows the day 1 sum as 10 and the day two sum as 15).
This is obviously because my array_sum is outside the while but if I were to put it inside the while, it wouldn't help because it's only dealing with the one record.
I'm scratching my head on this one -- not something I've ever had a reason to work with before. Any ideas?
Thanks in advance!
Array ( [0] => 04.04.2011 [1] => 04.05.2011 [2] => 04.06.2011 [3] => 04.07.2011 [4] => 04.08.2011 [5] => 04.09.2011 )
For each of the dates in the array, I want to run a query that returns the average a column:
foreach ($dateMonthYearArr as $csm_sum_for_date){
$i=0;
//Run query and calc occ average for each day
echo "Date - $csm_sum_for_date<br />";
$drillq = mysql_query("$csm_query statistic_date='$csm_sum_for_date' LIMIT 700" );// or die(mysql_error());
while($row_drillq = mysql_fetch_array( $drillq )) {
$i++;
$hnl_tme = $row_drillq['tlk_tme'] + $row_drillq['hld_tme'] + $row_drillq['acw_tme']; //correct!
$avl_tme_occ = $row_drillq['sum_avl_tme']/$row_drillq['cnt_ph_skll']; //correct!
$occ = $hnl_tme+$avl_tme_occ;
$csm_occ = $hnl_tme/$occ*100;//For csm averaging
$occ = $hnl_tme/$occ*100; //correct!
$occ = round("$occ", 0);
$stat_date = $row_drillq['statistic_date'];
$csm_occ_array[] = "$csm_occ";//For csm averaging
echo "$i - $csm_occ | $row_drillq[agent]<br />";
}//while
print_r ($csm_occ_array);
$csm_daily_occ_sum = array_sum($csm_occ_array);
$csm_daily_occ_sum_percent = $csm_daily_occ_sum/$i;
$csm_daily_occ_sum_percent = round("$csm_daily_occ_sum_percent", 0);
echo "<br /><b>$i - $csm_daily_occ_sum - $csm_daily_occ_sum_percent% </b><br /><br />";
}//foreach
The problem I have is that I'm not sure how to get the percentage and sum for EACH day individually. What I have compounds the averages and sum as it progresses (for example: if day 1 = 10 and day 2 = 5, it shows the day 1 sum as 10 and the day two sum as 15).
This is obviously because my array_sum is outside the while but if I were to put it inside the while, it wouldn't help because it's only dealing with the one record.
I'm scratching my head on this one -- not something I've ever had a reason to work with before. Any ideas?
Thanks in advance!