$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
My table looks like this ^
when i run that while loop it will gather these data
22
3
12
14
My question is since it does it in a loop it echoes it out separetly so how can i take all those values and add them up so 22 + 3 + 12 + 14 = 51?
Try something like following:
$count = 0;
while($row = mysqli_fetch_array($result))
{
$count += $row['start'];
}
echo $count; // 51
http://www.w3schools.com/sql/sql_func_sum.asp
SELECT SUM(column_name) FROM table_name;