Add Up All Mysql Values PHP
Hey, I have a tables called downloads, and in that table it stores the total amount of downloads for each day, so like
downloads date
586 07-16-2010
906 07-17-2010
1019 07-18-2010
287 07-19-2010
15 07开发者_运维问答-20-2010
639 07-21-2010
337 07-22-2010
How could I retrieve the total number of downloads, so add them all up from every single day :)
Thanks!
Would you believe it's as simple as
select sum(downloads) as total_downloads
from downloads
EDIT
$query = 'select sum(downloads) as total_downloads from downloads';
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$row = mysql_fetch_assoc($result);
$total_downloads = $row['total_downloads'];
精彩评论