I am trying to select a column from a table, not only display each row with its value but also display the total of the column according to the query.
As shown in the code provided below, each row is displayed perfectly, however, when comes to the total of the column, only the value of the first called row is displayed as a total.
Please look at the picture provided below. Only the first row selected with value of 25:18 is displayed as a total.
The expected total value at the bottom of the table should be 51:19+50:41+25:18, but the total again is just the first row (DESC). Please advise
table display after selected from sql
if (($user != "") && ($date !="")){
$mysql=("SELECT inet_ntoa(conv(hex(location_ip), 16, 10)) as ip, conv(hex(idvisitor), 16, 10) as visitorId,
visit_last_action_time, visit_first_action_time, visitor_localtime, user_id, visit_total_time
FROM piwik_log_visit WHERE user_id='".$user."' AND date(visit_first_action_time) ='".$date."'
Order by visit_first_action_time DESC");}
$query= mysqli_query($conn, $mysql) or die ("SQL Error: ".mysqli_error($conn));
while ($row = mysqli_fetch_array($query))
{
$time =date('F d, Y | h:i:s a', strtotime($row['visitor_localtime']));
$time =date('h:i:s a', strtotime($row['visitor_localtime']));
$idaction_url = $row['idaction_url'];
$ip =$row['ip'];
$visitor = $row['visitorId'];
$first = date('F d, Y |', strtotime($row['visit_first_action_time']));
$date = $first.' '.$time;
///total time added
$sum = array($row['visit_total_time']);
$sum_total = array_sum($sum);
$sum_time = gmdate('H:i:s', $sum_total);
$total = gmdate('i:s', $row['total_time']);