doudi8525 2015-12-22 18:46
浏览 39
已采纳

行的总和

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;        
    }
?>
  • 写回答

1条回答 默认 最新

  • dongyue5686 2015-12-22 18:49
    关注

    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>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比