i got this problem with the grand total in the table.
-------------------------------------------------------
may'01 june'01 july'01 august'01| sub total
file1 1 1 0 0 | 2
file2 2 0 0 0 | 2
file3 3 0 0 0 | 3
-------------------------------------------------------
grandtotal 6 7 7 7 7
-------------------------------------------------------
i guess when u look at this table u know whats is wrong. the grand total for each month is incorrect. i guess its the loop problem, pls help me to figure out where gone wrong in my scripts.
%SUBTOTAL = ();
$grand_total = 0;
$noRec=1;
$stmt = "select count(*) from TB_DOWNLOAD where FILE_ID=? AND DATE_DOWNLOAD>=? and DATE_DOWNLOAD<?";
$sth = $dbh->prepare($stmt);
foreach $H_FILE_ID (sort { $a <=> $b }keys %ALL_FILE_ID) {
$H_FILE_TITLE = $ALL_FILE_ID{$H_FILE_ID};
print qq(<tr>\n);
print qq( <td align="center"><font size="2" face="Arial">$noRec</font></td>\n);
print qq( <td><font size="1" face="Arial">$H_FILE_TITLE</font></td>\n);
$sub_total = 0;
for($zz=0;$zz<$F_PERIOD;$zz++) {
($LOOP_START_DATE_YEAR,$LOOP_START_DATE_MONTH,$LOOP_START_DATE_DAY) = Add_Delta_YMD($F_START_DATE_YEAR,$F_START_DATE_MONTH,$F_START_DATE_DAY, 0,$zz,0);
($LOOP_END_DATE_YEAR,$LOOP_END_DATE_MONTH,$LOOP_END_DATE_DAY) = Add_Delta_YMD($LOOP_START_DATE_YEAR,$LOOP_START_DATE_MONTH,$LOOP_START_DATE_DAY, 0,1,0);
$sth->execute($H_FILE_ID,"$LOOP_START_DATE_YEAR-$LOOP_START_DATE_MONTH-$LOOP_START_DATE_DAY","$LOOP_END_DATE_YEAR-$LOOP_END_DATE_MONTH-$LOOP_END_DATE_DAY"
;
if($row_ref = $sth->fetchrow_arrayref) {
$month_total = $row_ref->[0];
$sub_total += $month_total;
$SUBTOTAL{$zz} += $sub_total;
$month_total = commify($month_total);
print qq( <td width="$col_width" align="right"><font size="1" face="Arial">$month_total </font></td>\n);
}
}
$grand_total += $sub_total;
$sub_total = commify($sub_total);
print qq( <td align="right"><font size="1" face="Arial">$sub_total </font></td>\n);
print qq(</tr>\n);
$noRec++;
}
$sth->finish;
if ($noRec==0) {
print qq(<tr>\n);
print qq( <td colspan="$table_colspan" align="center"><font size="2" face="Arial"><br>There are no entries to display.</br> </font></td>\n);
print qq(</tr>\n);
}
$grandtotal_colspan = 2 if $noRec != 0;
# print grand total
$grand_total = sprintf("%d",$grand_total);
$grand_total_format = commify($grand_total);
print qq(<tr>\n);
print qq( <td bgcolor="#C0C0C0" colspan="2"><font size="2" face="Arial">Grand Total</font></td>\n);
@sort_keys = sort {$a <=> $b} (keys %SUBTOTAL);
foreach $ttl (@sort_keys) {
$grandsubtotal_format = commify($SUBTOTAL{$ttl});
$grandsubtotal_format = "$grand_total" if $grandsubtotal_format ne '0';
print qq( <td bgcolor="#C0C0C0" align="right"><font size="1" face="Arial">$grandsubtotal_format </font></td>\n);
-------------------------------------------------------
may'01 june'01 july'01 august'01| sub total
file1 1 1 0 0 | 2
file2 2 0 0 0 | 2
file3 3 0 0 0 | 3
-------------------------------------------------------
grandtotal 6 7 7 7 7
-------------------------------------------------------
i guess when u look at this table u know whats is wrong. the grand total for each month is incorrect. i guess its the loop problem, pls help me to figure out where gone wrong in my scripts.
%SUBTOTAL = ();
$grand_total = 0;
$noRec=1;
$stmt = "select count(*) from TB_DOWNLOAD where FILE_ID=? AND DATE_DOWNLOAD>=? and DATE_DOWNLOAD<?";
$sth = $dbh->prepare($stmt);
foreach $H_FILE_ID (sort { $a <=> $b }keys %ALL_FILE_ID) {
$H_FILE_TITLE = $ALL_FILE_ID{$H_FILE_ID};
print qq(<tr>\n);
print qq( <td align="center"><font size="2" face="Arial">$noRec</font></td>\n);
print qq( <td><font size="1" face="Arial">$H_FILE_TITLE</font></td>\n);
$sub_total = 0;
for($zz=0;$zz<$F_PERIOD;$zz++) {
($LOOP_START_DATE_YEAR,$LOOP_START_DATE_MONTH,$LOOP_START_DATE_DAY) = Add_Delta_YMD($F_START_DATE_YEAR,$F_START_DATE_MONTH,$F_START_DATE_DAY, 0,$zz,0);
($LOOP_END_DATE_YEAR,$LOOP_END_DATE_MONTH,$LOOP_END_DATE_DAY) = Add_Delta_YMD($LOOP_START_DATE_YEAR,$LOOP_START_DATE_MONTH,$LOOP_START_DATE_DAY, 0,1,0);
$sth->execute($H_FILE_ID,"$LOOP_START_DATE_YEAR-$LOOP_START_DATE_MONTH-$LOOP_START_DATE_DAY","$LOOP_END_DATE_YEAR-$LOOP_END_DATE_MONTH-$LOOP_END_DATE_DAY"

if($row_ref = $sth->fetchrow_arrayref) {
$month_total = $row_ref->[0];
$sub_total += $month_total;
$SUBTOTAL{$zz} += $sub_total;
$month_total = commify($month_total);
print qq( <td width="$col_width" align="right"><font size="1" face="Arial">$month_total </font></td>\n);
}
}
$grand_total += $sub_total;
$sub_total = commify($sub_total);
print qq( <td align="right"><font size="1" face="Arial">$sub_total </font></td>\n);
print qq(</tr>\n);
$noRec++;
}
$sth->finish;
if ($noRec==0) {
print qq(<tr>\n);
print qq( <td colspan="$table_colspan" align="center"><font size="2" face="Arial"><br>There are no entries to display.</br> </font></td>\n);
print qq(</tr>\n);
}
$grandtotal_colspan = 2 if $noRec != 0;
# print grand total
$grand_total = sprintf("%d",$grand_total);
$grand_total_format = commify($grand_total);
print qq(<tr>\n);
print qq( <td bgcolor="#C0C0C0" colspan="2"><font size="2" face="Arial">Grand Total</font></td>\n);
@sort_keys = sort {$a <=> $b} (keys %SUBTOTAL);
foreach $ttl (@sort_keys) {
$grandsubtotal_format = commify($SUBTOTAL{$ttl});
$grandsubtotal_format = "$grand_total" if $grandsubtotal_format ne '0';
print qq( <td bgcolor="#C0C0C0" align="right"><font size="1" face="Arial">$grandsubtotal_format </font></td>\n);