嘿,我有一个名为downloads的表,在该表中它存储了每天的下载总量,所以像
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
我如何检索下载总数,因此每天都要将它们全部添加:)
谢谢!
答案 0 :(得分:4)
您是否相信它就像
一样简单select sum(downloads) as total_downloads
from downloads
修改强>
$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'];