Generate two XLS Files

Asked

Viewed 38 times

0

I need to generate two files with different names and data in a PHP page, but the code only generates the second, follows a short excerpt of the code:

// Primeiro Arquivo

       for($i=0;$i<1;$i++){   
        $html[$i] .= "<table>";
        $html[$i] .= "<tr>";
        $html[$i] .= "<td><b>Nome</b></td>";
        $html[$i] .= "<td><b>Email</b></td>";
        $html[$i] .= "<td><b>Status do cliente</b></td>";
        $html[$i] .= "</tr>";
        $html[$i] .= "</table>";
    }

    $i = 1;
    $sql = "SELECT * FROM cadastros";
    $result = $conn->query($sql);
    while($ret = $result->fetch_assoc()) {


        $nome_cad = $ret['nome_cad'];
        $email_cad = $ret['email_cad'];
        $html[$i] .= "<table>";
        $html[$i] .= "<tr>";
        $html[$i] .= "<td>$nome_cad</td>";
        $html[$i] .= "<td>$email_cad</td>";
        $html[$i] .= "<td>Pagseguro</td>";
        $html[$i] .= "</tr>";
        $html[$i] .= "</table>";
        $i++;
    }
    $arquivo = 'dados.xls';
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
    header ("Cache-Control: no-cache, must-revalidate");
    header ("Pragma: no-cache");
    header ("Content-type: application/x-msexcel");
    header ("Content-Disposition: attachment; filename={$arquivo}" );
    header ("Content-Description: PHP Generated Data" );

    for($i=0;$i<=$result->num_rows;$i++){  
        echo $html[$i];
    }


    // Segundo arquivo -------------------------------


    for($ia=0;$ia<1;$ia++){   
        $html[$ia] .= "<table>";
        $html[$ia] .= "<tr>";
        $html[$ia] .= "<td><b>Pessoa</b></td>";
        $html[$ia] .= "<td><b>Data de contato</b></td>";
        $html[$ia] .= "<td><b>Hora contato</b></td>";
        $html[$ia] .= "<td><b>Status do contato</b></td>";
        $html[$ia] .= "<td><b>Detalhe do Contato</b></td>";
        $html[$ia] .= "</tr>";
        $html[$ia] .= "</table>";
    }

    $ia = 1;
    $sql = "SELECT * FROM cadastros WHERE situacao_pagseguro = 'aprovado'";
            $result = $conn->query($sql);
    while($ret = $result->fetch_assoc()) {


        $data_pagseguro = $ret['data_pagseguro'];
        $id_cad = $ret['id_cad'];

        $html[$ia] .= "<table>";
        $html[$ia] .= "<tr>";   
        $html[$ia] .= "<td>$data_pagseguro</td>";
        $html[$ia] .= "<td>$id_cad</td>";   
        $html[$ia] .= "</tr>";
        $html[$ia] .= "</table>";
        $ia++;
    }
    $arquivo = "retorno_pago.xls';
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
    header ("Cache-Control: no-cache, must-revalidate");
    header ("Pragma: no-cache");
    header ("Content-type: application/x-msexcel");
    header ("Content-Disposition: attachment; filename={$arquivo}" );
    header ("Content-Description: PHP Generated Data" );

    for($ia=0;$ia<=$result->num_rows;$ia++){  
        echo $html[$ia];
    }
  • Has syntax errors ai @Marcos

  • must have been at the time of editing to put here, this in the generation name of aqruivo $file = "retorno_pago.xls'; I left a double quotes,

No answers

Browser other questions tagged

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