How to use foreach with mPdf library?

Asked

Viewed 396 times

0

Hello, my friends.

I’m in a tough spot, I know what it is, but I can’t fix it.

Well, I’m using the mPDF library to generate reports, it’s great and very simple to use. I am bringing information from the database and saving in a table and it is she who is to appear in the report, however only generates the last line of this table and this is obvious, because it does not have a repetition structure (foreach I am using) in it, consequently does not bring all the bank information.

This is my code:

<?php
    include("mpdf60/mpdf.php");
    require_once ('../Controller/crudComissao.php');

   $idFuncionario = $row['idFuncionario'];
   $nomeFuncionario = $row['nomeFuncionario'];
   $valor = $row['valor'];

if (isset($_POST['btImprimir'])) {
$html = "
     <fieldset>
        <div class='container'>
        <div class='text-center'>
         <img src='img/logorelatorio.png' >
        </div>
        <br>
        <h3>Comissões</h3>
         <table class='table table-hover table-bordered'>
                <thead>
                    <tr>
                        <th class='text-center'>Código</th>
                        <th class='text-center'>Nome do Corretor</th>
                        <th class='text-center'>Mês</th>
                        <th class='text-center'>Valor(R$)</th>
                    </tr>
                </thead>                   

                    <tr>
                        <td class='text-center'> $idFuncionario </td>
                        <td class='text-center'> $nomeFuncionario</td>
                        <td class='text-center'> $mes_nome </td>
                        <td class='text-center'>R$ $valor </td>
                    </tr>
                <tfoot>
                    <tr>
                        <td></td>
                        <td></td>
                        <td align='right'>Total</td>
                        <td align='center'>R$ $sum </td>
                    </tr>
                </tfoot>
                </table>
            </div>
     </fieldset>";

    $mpdf=new mPDF(); 
    $mpdf->SetDisplayMode('fullpage');
    $css = file_get_contents("css/cavalaro.css");
    $css = file_get_contents("css/bootstrap-3.3.6-dist/css/bootstrap.css");
    $mpdf->WriteHTML($css,1);
    $mpdf->WriteHTML($html);
    $mpdf->Output("comissao.pdf",'D');
}

?>

I hope I’ve been clear. Thank you.

  • I’m also having the same problem. What I’m trying to do is finish html and start php and then I concatenate the variables. $mpdf->Writehtml($html."". $html2."". $html3);

  • $css = file_get_contents("css/cavalaro.css"); $css = file_get_contents("css/bootstrap-3.3.6-dist/css/bootstrap.css"); Two variables cannot receive different values pq vc will be overwriting its value.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.