1
I have a table that is returned with the while
and created filters in it with excelTableFilter
. Now when filtering in the table I wanted to add the total quantity * the price.
Code:
$tabela1 .= '<table border="5" class="teste1" method="POST" id="table">';
$tabela1 .='<thead>';
$tabela1 .= '<tr>';
$tabela1 .= '<th class="filter" style="width:42px; text-align: center; font-size: 12px">Quantidade</th>';
$tabela1 .= '<th class="filter" style="width:25px; text-align: center; font-size: 12px">Preço</th>';
$tabela1 .= '</tr>';
$tabela1 .='</thead>';
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$tabela1 .= '<tbody>';
$tabela1 .= '<tr>';
$tabela1 .= '<td style="font-size: 12px"> '.$rows_cursos['Preco'].'</td>';
$tabela1 .= '<td style="font-size: 12px"> '.$rows_cursos['Quantidade'] * $rows_cursos['Preco'].'€</td>';
$tabela1 .= '</tr>';
}
I create the filters in the table as follows:
$(function(){
$('#table').excelTableFilter();
});
I intend that when consulting by invoice within the table, at the bottom of the table show the total amount * price of the total of the returned lines.
I did it in php, this way:
$Total = 0;
while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {
$Total = $Total + ($rows_cursos['Quantidade'] * $rows_cursos['Preco']);
}
$tabela1 .= '<tr>';
$tabela1 .= '<td colspan="9" style="text-align: right;">';
$tabela1 .= '<strong>Valor Total:</strong> '. $Total .'€';
$tabela1 .= '</td>';
$tabela1 .= '</tr>';
But this way only works when I filter outside the table, when I filter inside the table through the function I posted above, the returned value is wrong