ok, I have a script that that gets date ranges from a database to display as part of another script. I need to modify this script to display annual totals for the optgroup. This is the code as I have it now
[php]$com_cont = ‘’;
$qry_a = mysql_query(“SELECT start_date, end_date FROM venzo_app_sales
WHERE title IN (SELECT appname FROM venzo_user_apps WHERE uid = '”.$_SESSION[‘uid’]."’)
GROUP BY start_date ORDER BY STR_TO_DATE(start_date,’%m/%d/%Y’) desc"
) or die(mysql_error());
$sub = array();
$sub[] = “”;
$com_cont.='Select Date Range: ';
while($r = mysql_fetch_array($qry_a)) {
$tm = explode('/', $r['start_date']);
$yr = $tm[2];
$dte = $r['start_date']. " - " .$r['end_date'];
$qry = mysql_query("SELECT partner_share_currency, extended_partner_share_currency AS psc FROM venzo_app_sales
WHERE title IN (SELECT appname FROM venzo_user_apps WHERE uid = '".$_SESSION['uid']."')");
while($as = mysql_fetch_array($qry)) {
//$as = mysql_fetch_array($qry);
$as['total'] = $as['psc'] * $arr_currency[$as['partner_share_currency']];
}
//if($prev_yrs == $yr) {
$abs_total += $as['total'];
// $prev_yrs = $tm[2];
//}
if($prev_yr != $yr) {
$sub[] = "<optgroup label='$yr ($".number_format($abs_total, 2).")'>";
$prev_yr = $tm[2];
}
$sub[] = "<option value='$dte'>$dte</option>";
if($prev_yr != $yr) {
$sub[] = "</optgroup>";
$prev_yr = $tm[2];
}
}
$sub[] = “”;
for($k = 0; $k < count($sub); $k++) {
$com_cont.= $sub[$k];
}[/php]
This displays something like
2013
09/01/2013 - 09/30/2013
08/01/2013 - 08/31/2013
etc
2012
etc
2011
and so on
What I have to do is get the annual totals to display next to the year, so I end up with
2013 ($1000.00)
09/01/2013 - 09/30/2013
08/01/2013 - 08/31/2013
etc
2012 ($800.00)
etc
2011 ($100.00)
and so on
I’ve gotten it to return values, but they’re never correct. I know i’m close, but can’t figure out what i’m doing wrong. Any help would be greatly appreciated.