ID sum reset to the first line.

1

Could anyone explain why the sum of my first ID in the commissions column appears zero? The value of the sum of ID 1 goes to ID 2 ..... and ID 2 to line 3, and so on. Here is my code:

<?php

    if(!empty($resultado)) { 
        foreach($resultado as $row ) {

    ?>
      <tr>
        <td><center><?php echo "0" .$row["id"]; ?></center></td>
        <td><?php $date = date_create($row["post_at"]); echo date_format($date, 'd/m/y');?></td>
        <td><div style="text-align: left;"><?php echo $row["cliente"]; ?></div></td>
        <td><div style="text-align: left;"><?php echo $row["prod_1"]; ?></div></td>
        <td><div style="text-align: right;"><?php echo "R$ " . number_format( $sub1 / 100 * 5, 2, ',', '.'); ?></div></td>


        <td><div style="text-align: center;">

        <?php 

        if($row["status"] == "Finalizada"){
        echo "<div class='badge badge-success' style='width:80px'>";

        }
        If($row["status"] == "Cancelada") {
        echo "<div class='badge badge-danger'style='width:80px'>";
        }
        If ($row["status"] == "Aguardando") {
        echo "<div class='badge badge-warning' style='width:80px'>";
        }
        echo $row["status"];?>

        </div></td>

        <td style="text-align: right;"> R$  <?php echo number_format($sub1 = $row['valor_1'] * $row['qtde_1'] + $row['valor_2'] * $row['qtde_2'] + $row['valor_3'] * $row['qtde_3'] + $row['valor_4'] * $row['qtde_4'], 2, ',', '.'); ?> </td>
        <?php $total = $sub1?>
        <td>
            <a class="btn btn-outline-dark btn-sm" id="imprimir" title="Imprimir" href='print.php?id=<?php echo $row['id']; ?>'><span class="fa fa-print"></span></a> 
            <a class="btn btn-outline-dark btn-sm" title="Visualizar" href='view.php?id=<?php echo $row['id']; ?>'><span class="fa fa-eye"></span></a> 
            <a class="btn btn-success btn-sm" title="Editar" href='edit.php?id=<?php echo $row['id']; ?>'><span class="fa fa-edit"></span></a> 
            <a class="btn btn-danger btn-sm" title="Deletar" href='delete.php?id=<?php echo $row['id']; ?>'><span class="fa fa-trash"></span></a>
        </td>
      </tr>




    <?php
        }
    }

    ?>

    
asked by anonymous 18.05.2018 / 19:51

0 answers