$oneweek = date("Y-m-d",strtotime("-1 week"));
$currentdate = date("Y-m-d");
$result = mysqli_query($con, "SELECT * FROM `76561198047786230` WHERE date >= '$oneweek' AND date <= '$currentdate'");
while($row = mysqli_fetch_array($result)) {
echo $row['start'];
}
id start end date
2 22 23:18 2014-07-03 22:09:16
3 3 03:43 2014-07-04 03:09:10
4 12 13:38 2014-07-04 12:04:19
5 14 16:43 2014-07-04 14:08:53
我的表看起来像这样^
当我运行while循环时,它将收集这些数据
22
3
12
14
我的问题是,因为它在一个循环中完成,它会逐渐回复它,所以我怎样才能将所有这些值加起来并将它们加起来以便22 + 3 + 12 + 14 = 51?
答案 0 :(得分:0)
尝试以下内容:
$count = 0;
while($row = mysqli_fetch_array($result))
{
$count += $row['start'];
}
echo $count; // 51
答案 1 :(得分:0)
http://www.w3schools.com/sql/sql_func_sum.asp
SELECT SUM(column_name) FROM table_name;