Show variable in specific place with a div

1

I have this while where I created a variable before the while to get the total of a column:

$Total = 0;

    while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {

        $teste = $rows_cursos['Horas Consumidas'];
        $Total = $Total + $teste;

$tabela3 .= '<tr>';

$tabela3 .= '<td>'.$rows_cursos['DataRegisto'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['codigoutente'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['nome'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['descricaovalencia'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Data'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Inicio'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Fim'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Colaborador'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Horas Consumidas'].'</td>';

$tabela3 .= '</tr>'; 

}

$tabela3 .= '</tr>';

$tabela3 .='</tbody>'; 

$tabela3 .= '</table>';

$tabela3 .= '</div>';

echo $tabela3;

echo '<strong>Total de Horas Consumidas:</strong> '. $Total;

But this result that appears surrounded by red, wanted it to appear under the last column of the table as the arrow points, since it is the sum of the hours in that column.

    
asked by anonymous 09.04.2018 / 17:13

1 answer

1

Notice that after while you are closing </tr> unnecessarily:

$tabela3 .= '</tr>'; 

}

$tabela3 .= '</tr>'; <-- fechando novamente a TR

Lines are already closed within while .

In place of this line $tabela3 .= '</tr>'; you can insert a new line with <td colspan="9"> , where 9 represents the number of columns, creating a line with only <td> covering the 9 columns of the table. Also enter align="right" to align the text to the right. The code looks like this:

while($rows_cursos = mysqli_fetch_array($resultado_cursos)) {

        $teste = $rows_cursos['Horas Consumidas'];
        $Total = $Total + $teste;

$tabela3 .= '<tr>';

$tabela3 .= '<td>'.$rows_cursos['DataRegisto'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['codigoutente'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['nome'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['descricaovalencia'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Data'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Inicio'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Fim'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Colaborador'].'</td>';

$tabela3 .= '<td>'.$rows_cursos['Horas Consumidas'].'</td>';

$tabela3 .= '</tr>'; 

}

$tabela3 .= '<tr>';
$tabela3 .= '<td colspan="9" align="right">';
$tabela3 .= '<strong>Total de Horas Consumidas:</strong> '. $Total;
$tabela3 .= '</td>';
$tabela3 .= '</tr>';

$tabela3 .='</tbody>'; 

$tabela3 .= '</table>';

$tabela3 .= '</div>';

echo $tabela3;
    
09.04.2018 / 17:36