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

0

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

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

    
asked by anonymous 18.11.2016 / 19:38

1 answer

1

Your inputs have names repeated on each line

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

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

If you make the names as arrays :

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

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

EDIT adding implementation

To generate the 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>";
    
18.11.2016 / 22:38