displaying totals

I’ve hit a brick wall on this one. I’m trying to get this script to display total units sold, but for whatever reason, its giving me two results

App Sales
Total Sales: 7,591.37
Total Sales: 0.00

The code i’m using is from a regular trends page that we have. I had to change its input since the user isn’t telling telling it which app to look at. Its supposed to loop through all the user’s apps. I think it is now, but i can’t get rid of the double results.

code
[php]
$fl = mysql_query(“SELECT appname FROM venzo_user_apps WHERE uid = $_SESSION[uid]”);

while($r = mysql_fetch_array($fl)) {
$label_a = $r[‘appname’];

$qry = mysql_query("SELECT title, partner_share_currency, extended_partner_share_currency AS psc FROM venzo_app_sales WHERE title = '{$label_a}'") or die(mysql_error());

while($row = mysql_fetch_assoc($qry)) {
	switch($row['partner_share_currency']) {
		case 'EUR':
			$sym = "€ ";
			$row['psc_int'] = $row['psc'] * 0.813460 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.813460 / 2, 2);
			break;
		case 'USD':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] / 2;
			$row['psc'] = "$".number_format($row['psc'] / 2, 2);
			break;
		case 'CAD':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.964782 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.964782 / 2, 2);
			break;
		case 'GBP':
			$sym = "£ ";
			$row['psc_int'] = $row['psc'] * 1.46867 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 1.46867 / 2, 2);
			break;
		case 'JPY':
			$sym = "¥ ";
			$row['psc_int'] = $row['psc'] * 0.0108447 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.0108447 / 2, 2);
			break;
		case 'AUD':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.847417 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.847417 / 2, 2);
			break;
		case 'NZD':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.684454 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.684454 / 2, 2);
			break;
		case 'MXN':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.0783349 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.0783349 / 2, 2);
			break;
		case 'CHF':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 1.11174 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 1.11174 / 2, 2);
			break;
		case 'CNY':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.158328 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.158328 / 2, 2);
			break;
		case 'NOK':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.177831 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.177831 / 2, 2);
			break;
		case 'DKK':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.18229 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.18229 / 2, 2);
			break;
		case 'SEK':
			$sym = "$ ";
			$row['psc_int'] = $row['psc'] * 0.14949 / 2;
			$row['psc'] = "$".number_format($row['psc'] * 0.14949 / 2, 2);
			break;
	}
	$rows[$row['label']][] = $row;
}

	
if(mysql_num_rows($qry) != 0) {
	foreach($rows as $key => $row) {
		for($i = 0 ; $i < count($row) ; $i++)
			$rows[$key]['total'] += $row[$i]['psc_int'];
	}
	$dolist = true;
}

}
?>

App Sales
<?php if(isset($dolist)) { foreach($rows as $key => $row) { ?>
	<div><?php echo "Total Sales: ".number_format($row['total'], 2); ?></div>
<?php } } ?>[/php]

I’m trying to get it to do this

App Sales
Total Sales: 7,591.37

Any help would be appreciated.

Well i’m not sure what’s going on. I managed to get 1 of the results to be correct, but i still can’t get rid of the doubles

App Sales
Total Sales: 15,182.75
Total Sales: 827.10

The 827.10 is what it should be for that particular user. The first one is no where near correct, not even sure where its getting it, we don’t have sales that high for apps yet.

I got it fixed. It was a very stupid error on my part. I ended up doing a print_r on $rows to see what it contained. from that display, i realized that i just had to unset $rows because it was being used twice (there’s an almost identical script above that code for music sales).

Once i unset it, it worked.

Sponsor our Newsletter | Privacy Policy | Terms of Service