2
I make the total sum as follows in while
:
$TotalSIva6 = 0;
$TotalSIva7 = 0;
$TotalCIva6 = 0;
$TotalCIva7 = 0;
while($rows_cursos3 = mysqli_fetch_array($result3)) {
$teste24 = $rows_cursos3['Valor'];
$teste25 = $rows_cursos3['Valor1'];
$TotalSIva6 = $TotalSIva6 + $teste24;
$TotalSIva7 = $TotalSIva7 + $teste25;
$TotalCIva6 = $TotalCIva6 + $TotalSIva6;
$TotalCIva7 = $TotalCIva7 + $TotalSIva7;
$tabela4 .= '<tr>';
$tabela4 .= '<td>'.$rows_cursos3['Bolacha M DI'].'</td>';
$tabela4 .= '<td>'.$rows_cursos3['Quantidade Bolacha'].'</td>';
$tabela4 .= '<td>'.$rows_cursos3['Valor'].'</td>';
$tabela4 .= '</tr>';
$tabela4 .= '<tr>';
$tabela4 .= '<td>'.$rows_cursos3['Bolacha AS D'].'</td>';
$tabela4 .= '<td>'.$rows_cursos3['Total Bolacha AS'].'</td>';
$tabela4 .= '<td>'.$rows_cursos3['Valor1'].'</td>';
$tabela4 .= '</tr>';
$TotalSIva8 = 0;
$TotalCIva8 = 0;
while($rows_cursos5 = mysqli_fetch_array($result5)) {
$teste26 = $rows_cursos5['Valor'];
$teste27 = $rows_cursos5['Iva'];
$TotalSIva8 = $TotalSIva8 + $teste26;
$TotalCIva8 = $TotalCIva8 + $teste27;
$tabela4 .= '<tr>';
$tabela4 .= '<tr>';
$tabela4 .= '<td>'.$rows_cursos5['ProdExtras'].'</td>';
$tabela4 .= '<td>'.$rows_cursos5['Total'].'</td>';
$tabela4 .= '<td>'.$rows_cursos5['Valor'].'</td>';
$tabela4 .= '</tr>';
$tabela4 .= '<tr>';
$TotalSIva9 = 0;
$TotalCIva9 = 0;
while($rows_cursos4 = mysqli_fetch_array($result4)) {
$teste28 = $rows_cursos4['Valor'];
$teste29 = $rows_cursos4['Iva'];
$TotalSIva9 = $TotalSIva9 + $teste28;
$TotalCIva9 = $TotalCIva9 + $teste29;
$tabela5 .= '<tr>';
$tabela5 .= '<td>'.$rows_cursos4['ProdExtras'].'</td>';
$tabela5 .= '<td>'.$rows_cursos4['Total'].'</td>';
$tabela5 .= '<td>'.$rows_cursos4['Valor'].'</td>';
$tabela5 .= '</tr>';
$tabela5 .= '<tr>';
}
}
$TotalSIva8 = $TotalSIva8 + $TotalSIva6 + $TotalSIva7;
$TotalCIva6 = $TotalCIva6*1.06;
$TotalCIva7 = $TotalCIva7*1.13;
$TotalCIva8 = $TotalCIva8 + $TotalCIva6 + $TotalCIva7;
$tabela4 .= '<tr>';
$tabela4 .= '<td colspan="3" style="text-align: right;">';
$tabela4 .= '<strong>Total S/Iva:</strong> '. $TotalSIva8 .'€';
$tabela4 .= '</td>';
$tabela4 .= '</tr>';
$tabela4 .= '<tr>';
$tabela4 .= '<td colspan="3" style="text-align: right;">';
$tabela4 .= '<strong>Total C/Iva:</strong> '. number_format($TotalCIva8, 2 , ',', ' ') .'€';
$tabela4 .= '</td>';
$tabela4 .= '</tr>';
$tabela4 .='</tbody>';
$tabela4 .= '</table>';
$tabela4 .= '</div>';
$tabela5 .= '<tr>';
$tabela5 .= '<td colspan="3" style="text-align: right;">';
$tabela5 .= '<strong>Total S/Iva:</strong> '. $TotalSIva9 .'€';
$tabela5 .= '</td>';
$tabela5 .= '</tr>';
$tabela5 .= '<tr>';
$tabela5 .= '<td colspan="3" style="text-align: right;">';
$tabela5 .= '<strong>Total C/Iva:</strong> '. number_format($TotalCIva9, 2 , ',', ' ') .'€';
$tabela5 .= '</td>';
$tabela5 .= '</tr>';
$tabela5 .='</tbody>';
$tabela5 .= '</table>';
$tabela5 .= '</div>';
echo $tabela5;
In the $tabela5
within the while
before the line $tabela5 .= '<tr>';
if made:
var_dump ($TotalSIva9);
var_dump ($TotalCIva9);
It returns the correct values:
(float(1) float(1.06) float(136.84) float(154.5592))
If you make the var_dump();
of variables outside the while
. He returns:
(int(0) int(0))
.
What will be the reason?
The values
Valor
andIva
collected from BD are always type number?– Wesley Gonçalves
The variables
$TotalSIva9
and$TotalCIva9
shall contain only the sum of the values of$teste28
and$teste29
concerning the last iteration ofwhile
outermost ($rows_cursos5
) because the two variables are receiving the zero value before starting the secondwhile
. Perhaps when the last iteration ofwhile
external values of thewhile
inner most are null.– Wesley Gonçalves