行的总和

I'm new to php and I'm stuck. I have a report that allows a supervisor to show the working hours of the operators. I can show all the hours from the db, but I can't make a sum of all the hours. I want to display one more row that shows the total hours. How can I do that?

<?php
    if(isset($_SESSION['username'])) {
        $username = $_SESSION['username'];
    } else {
        header('Location: index.php');
        die();
    }

    include('connect.php');

    @$oret_e_punes       = $_POST['oret_e_punes'];
    @$grupi              = $_POST['grupi'];
    @$data_e_inserimit   = $_POST['data_e_inserimit'];
    @$data_e_inserimit_2 = $_POST['data_e_inserimit_2'];

    $sql = "select grup_name from grupi";
    $result = mysqli_query($dbCon, $sql);
    if(!$result) {
    die("Error");
    }   
?>

//html form

<?php
    if(isset($_POST['insert'])) {
        $insert = "select * from ore where grupi='$grupi' and (data between '$data_e_inserimit' and '$data_e_inserimit_2' and ore !=0)";
        $result_insert = mysqli_query($dbCon, $insert);
        if(!$result_insert) {
            die("Error");
        }



    echo "<table id='table'>
        <tr id='main'>
        <td>Operatori</td>
        <td>Grupi</td>
        <td>Oret e punes</td>
        <td>Data</td>
        </tr>";
    while ($row = mysqli_fetch_assoc($result_insert)) {
        $id = $row['id'];
        echo "<tr id='sub'>
            <td>".$row['usr']."</td>
            <td>".$row['grupi']."</td>
            <td>".$row['ore']."</td> ---->working hours
            <td>".$row['data']."</td>
            </tr>";
            $id++;
    }
        echo "</table>";
        $_SESSION['$id'] = @$id;        
    }
?>

have a variable for hours before loop starts. Add in it hour of each record. After loop will end you will have your total hours

echo "<table id='table'>
    <tr id='main'>
    <td>Operatori</td>
    <td>Grupi</td>
    <td>Oret e punes</td>
    <td>Data</td>
    </tr>";
$hours = 0;
while ($row = mysqli_fetch_assoc($result_insert)) {
    $id = $row['id'];
    echo "<tr id='sub'>
        <td>".$row['usr']."</td>
        <td>".$row['grupi']."</td>
        <td>".$row['ore']."</td> ---->working hours
        <td>".$row['data']."</td>
        </tr>";
        $hours += $row['ore'];
        $id++;
}
echo "<tr><td colspan='4'>Total</td><td>$hours</td></tr>";
echo "</table>";