Report in mPDF only return a single record when receiving data via POST

Asked

Viewed 278 times

0

I am trying to generate a PDF with data sent via POST. insert link description here

The os-list.php file is a report that the data changes according to the filter. I am sending this data but only appears the last record.

inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

1 answer

1


Your inputs have names repeated in each row

<input type="hidden" name="OSid" value="<?=$OSid?>" />

In this case when you send the POST the browser will send only the last read value, the last page Names.

If you do the Names as arrays:

<input type="hidden" name="OSid[]" value="<?=$OSid?>" />

The $_POST['OSid'] will be a list of all ids sent, and so with all names.

EDIT adding implementation

To generate multi-line report:

<?php
    // Cada um desses valores agora é um array
     $OSid          = $_POST['OSid'];
     $dataHora      = $_POST['dataHora'];
     $nomeFantasia  = $_POST['nomeFantasia'];
     $NomeSetor     = $_POST['NomeSetor'];
     $motivoOs      = $_POST['motivoOs'];
     $TotalMaterial = $_POST['TotalMaterial'];
     $NomeTipoOS    = $_POST['NomeTipoOS'];
     $status        = $_POST['status'];



     $corpo_pagina = "

    <html>
        <head>
            <link href='css/bootstrap.css' media='print' rel='stylesheet'>
            <link href='css/estiloOS.css' media='print' rel='stylesheet' >
        </head>   
    <boby>
        <table border='1' class='table table-striped'>
            <tr>
                <th>ID</th>
                <th>DATA</th>
                <th>CLIENTE</th>
                <th>SETOR</th>       
                <th>MOTIVOS OS</th>
                <th>CUSTO TOTAL</th>
                <th>TIPO OS</th>
                <th>STATUS</th>
            </tr>";

            // Fazemos um laço pelo número de itens da lista
            // $OSid e imprimimos cada item em uma linha separada
            for( $i = 0; $i < count( $OSid ); $i++ ) {
                $corpo_pagina .= "
                    <tr>
                        <td>".$OSid[$i]."</td>
                        <td>".$dataHora[$i]."</td>
                        <td>".$nomeFantasia[$i]."</td>
                        <td>".$NomeSetor[$i]."</td>
                        <td>".$motivoOs[$i]."</td>
                        <td>".$TotalMaterial[$i]."</td>
                        <td>".$NomeTipoOS[$i]."</td>    
                        <td>".$status[$i]."</td>
                    </tr>";
            }

        $corpo_pagina .= "</table>";
  • Nothing wrong there in this array, no. Is returning the word array in all of them.

  • You must have to change the way the data is entered in the table. If you only use echo or print he prints Array. Now you need to reference the keys to print the correct value. Ex.: https://eval.in/680884

  • <td><? php $Osid = array(); $Osid[] = $os['id']; foreach($Osid as $valor_OSid): print_r($valor_OSid ); ? > <input type="Hidden" name="Osid[]" value="<?= $valor_OSid? >" /> <?php endforeach; ? > </td> Is displaying in the list but the pdf only appears the word array. Thanks.

  • I edited the reply by adding the implementation in the output of the report. The code you are showing believe that is the table on the screen, but the principle is the same.

  • I made the changes but is giving error when generating PDF document. I updated Gits. You said value is value="<?=$OSid?>" That’s right? Pq is the foreach($OSid as $valor_OSid): It would not be the value="<?=$valor_OSid?>" ?

  • https://gist.github.com/FabricioYwin/843377a186cc083887110bef057f007d

  • what error is giving?

  • Failed to Generate PDF document. Reload? Ai If you click, nothing happens.

  • Look at the print, pfv. http://imgur.com/a/Mgx5U

Show 5 more comments

Browser other questions tagged

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