Help with PHP (passing data from one screen to another)

0

I'm having a question on this part of php with passing data from one screen to another. I want to bring the data from the database resolver in php and generate a PDF for the user to check or download it.

On a screen I make the user type from the date x to x that he wants to fetch the results in the database.

enter image description here

Soon after I make a query for it to take the data and make a count and the percentage.

    <?php include "conexao.php"; ?>
<html>

    <head>
        <title></title>
    </head>

    <body>

        <h1>Pesquisa Teste</h1>
<form method="GET" action="gerar.php" target="_blank">
    Pesquisar data Inicial:<input type="date" name="data1" placeholder="Pesquisar">
    <br>
    Pesquisar data Final:<input type="date" name="data2" placeholder="Pesquisar">
    <input type="submit" value="Enviar" name="submit" >

        <?php

        $data1 = isset($_GET['data1']);
        $data2 = isset($_GET['data2']);


            $link = mysqli_connect("localhost", "root", "", "iam") or die (mysqli_error());
            $sql = "select count(id) AS ID, sum(agesimpatia='otimo') as AgesimpOTIMO, sum(agesimpatia='bom') as AgesimpBOM,sum(agesimpatia='ruim') as AgesimpRUIM, sum(agesimpatia='naoutilizei') as AgesimpNaoUti
            from form_votacao where datavotacao >= '$data1' and datavotacao <= '$data2' ;";
            $query = mysqli_query($link, $sql);
            $row = mysqli_num_rows($query);
            if($row > 0){
                while($linha = mysqli_fetch_array($query)){
                    $age_otimo = $linha['AgesimpOTIMO'];
                    $age_bom = $linha['AgesimpBOM'];
                    $age_ruim = $linha['AgesimpRUIM'];
                    $age_nu = $linha['AgesimpNaoUti'];
                    $age_total = $linha['ID'];
                    $age_final = $age_total - $age_nu;



                        if($age_total != 0){
                    $age_porotimo = round(($age_otimo * 100 ) / $age_total);
                    $age_porbom = round(($age_bom * 100 ) / $age_total);
                    $age_porruim = round(($age_ruim * 100 ) / $age_total);
                    $age_pornaouti = round(($age_nu * 100 ) / $age_total);
                    $age_portotal = round(($age_total * 100) / $age_total);




                    echo "Agendamento Otimo: $age_otimo";
                    echo $_GET['$age_otimo'];
                    echo "<br/>";
                    echo "Agendamento Bom: $age_bom";
                    echo "<br/>";
                    echo "Agendamento Ruim: $age_ruim";
                    echo "<br/>";
                    echo "Agendamento Não Utilizei: $age_nu";
                    echo "<br/>";
                    echo "Agendamento Total: $age_final";
                    echo "<br/>";

                    echo "<br/>";
                    echo "<hr/>";
                    echo "Agendamento Porcentagem de Otimo: " . number_format($age_porotimo) ."%";
                    echo "<br/>";
                    echo "Agendamento Porcentagem de Bom: " . number_format($age_porbom) ."%";
                    echo "<br/>";
                    echo "Agendamento Porcentagem de Ruim: " . number_format($age_porruim) ."%";
                    echo "<br/>";
                    echo "Agendamento Porcentagem de Não Utilizei: " . number_format($age_pornaouti) ."%";
                    echo "<br/>";

                    echo "<br/>";
                    echo "Agendamento Porcentagem Total: " . number_format($age_portotal)."%";
                    echo "<br/>";


                } else {
                    echo "<br/>";
                    echo "<br/>";
                    echo "Selecione a data acima que deseja procurar";
                }

            }
                } else {
                echo "Desculpe, ainda não existe registro ou conexão não está ativa!";
            }

            // $sendPesquisa = filter_input(INPUT_POST, 'submit', FILTER_SANITIZE_STRING);


            mysqli_close($link);

        ?>
        </form>
    </body>

</html>

Next page where the user is redirected to show the information only that is in bringing them in.

             REPORT GENERATOR

</head>

<body>
    <?php
        include "mpdf/mpdf.php";
        include "index.php";

        $data1 = $_GET['data1'];
        $data2 = $_GET['data2'];







        $pagina =

"<html method='GET'>
    <body>
        <h1>Pesquisa de Satisfação </h1>
        <h6>Filtro: Pesquisa da data: ".$data1." até ".$data2."</h6>
        <table border='1'>
        <tr>
        <td>Agendamento Simpatia Otimo:" .$age_otimo. "</td><br>
        <td>%Otimo:" .$age_porotimo. "</td><br>
        </tr>
        <tr>
        <td>TOTAL: " .$age_total. "</td>
        </tr>
        </table>
    </body>


    </html>
";

$arquivo = "gerar.pdf";
$mpdf = new mPDF();
$mpdf->WriteHTML($pagina);

$mpdf->Output($arquivo, 'I');
exit();

    ?>

</body>

GETTING THE IMAGE BELOW:

enter image description here

    
asked by anonymous 19.11.2018 / 02:55

1 answer

0

The problem is that the block of code that receives the information of the dates and does the query is in the wrong page, when you defined in the form that the action = gera.php it throws all the data there then the block of code that receives the date and does the select has to be in the page that you put the action and not in the beginning, to work by the method that you have chosen.

    
19.11.2018 / 05:38