This is extension of my previous question. My previous question solved my problem. the link How to calculate rows in query PHP MySQL?
But it only work if each row of query have different values (i.e 1st row = 1 and 2nd row = 1.5). only then it calculate these two rows.
It does not work and it cannot calculate if the row have the same value (i.e 1st row = 1 and 2nd row = 1). it only shows single row
The code as below
<?php
$sql = "SELECT sum_hour,
SUM(sum_hour)
FROM table
WHERE type_move = 'P' AND user_id='username' AND (start_date >= '2016-11-11' AND end_date <= '2016-11-15')
GROUP BY sum_hour ";
$result = mysqli_query($connect, $sql);
if($result && mysqli_num_rows($result) > 0)
{
$total = 0;
while($row = mysqli_fetch_assoc($result))
{
$hour = $row['sum_hour'];
$total += $hour;
echo " Hours = " .$hour. "<br/>";
print_r($row);
}
echo "Total hours = " .$total. "<br/>";
mysqli_free_result($result);
}
else
{
echo mysqli_error($connect);
}
?>
Can someone help ?
Thanks.
total = 0;will be$total = 0;