计算特定日期的行总数

时间:2022-12-04 08:52:11

I have this working.

我有这个工作。

 $queryPR = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'PR')";

I need the total amount of rows calculated for specific date.

我需要计算特定日期的总行数。

I need also to the SUM('pagesat') somehow but I have no idea how.

我也需要以某种方式进行求和('pagesat'),但我不知道怎么做。

Find the whole code below.

找到下面的整个代码。

I am trying to build something simple to show the income and outcome for 3 locations that we have.

我正在尝试构建一些简单的东西来显示我们拥有的3个地点的收入和结果。

<table class="responsive-table">
        <thead>
            <tr>
                <th>Vetura</th>
                <th>Targa</th>
                <th>Dite</th>
                <th>Pagesa</th>
                <th>Cmimi Ditore</th>
                <th>Vazhdim</th>
                <th>Te Tjera</th>
                <th>Shpenzime</th>
                <th>Komente</th>
            </tr>
        </thead>

        <tbody>
           <?php

                $query = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'FR')";

                $stmt = $DBcon->prepare( $query );
                $stmt->execute();

            while($row=$stmt->fetch(PDO::FETCH_ASSOC)){

            ?>
            <tr>
                <td><?php echo $row['vetura']; ?></td>
                <td><?php echo $row['targa']; ?></td>
                <td><?php echo $row['dite']; ?></td>
                <td><?php echo $row['pagesa']; ?>€</td>
                <td><?php echo $row['cmimiditore']; ?>€</td>
                <td><?php echo $row['vazhdim']; ?>€</td>
                <td><?php echo $row['tetjera']; ?>€</td>
                <td><?php echo $row['shpenzime']; ?>€</td>
                <td><?php echo $row['koment']; ?></td>
            </tr>
            <?php
                $pagesa = $row['pagesa'];
                $tetjera = $row['tetjera'];
                $vazhdime = $row['vazhdim'];
                $shpenzime = $row['shpenzime'];
            }?>
        </tbody>
    </table>

    <?php


        $totali = ($pagesa + $vazhdime + $tetjera);
        $gtotal = ($totali - $shpenzime);



    ?>
    <div class="card grey">
        <hgroup class="totalDitorRaport">
            <h2>Total</h2>
            <h1><?php echo $gtotal; ?>€</h1>
        </hgroup>
    </div>

1 个解决方案

#1


2  

try this

试试这个

get the sum of the row pagesa in the loop

获取循环中的行pagesa的总和

$queryPR = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'PR')";

$stmt = $DBcon->prepare( $query );
                $stmt->execute();

   $sum = 0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){

 $sum += $row['pagesa'];

 }
echo $sum;

#1


2  

try this

试试这个

get the sum of the row pagesa in the loop

获取循环中的行pagesa的总和

$queryPR = "SELECT * FROM `raport` WHERE DATE(`timestamp`) = CURDATE() AND (lokacioni = 'PR')";

$stmt = $DBcon->prepare( $query );
                $stmt->execute();

   $sum = 0;
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){

 $sum += $row['pagesa'];

 }
echo $sum;