开发者

Add Up All Mysql Values PHP

开发者 https://www.devze.com 2023-01-08 04:49 出处:网络
Hey, I have a tables called downloads, and in that table it stores the total amount of downloads for each day, so like

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'];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号