Table HTML printing

1

I'm developing an application in php with mysql and at a certain point I need to make an appointment in the database and bring the information into a table. Until then, I need to have the option of printing all the contents of the table, that is, print (on paper) a dynamic query.

I studied ireport but I am very difficult, and I would like to know if there is another way to generate this impression or not. In another part of the application I print certificates and it is very quiet, but ireport gives me the impression that I will have to do some gambiarras to use with php.

Here is an example of the table I'm using, and remembering that sometimes the search generates several pages.

 <table cellspacing="0" cellpadding="0" border="0" class="display" id="listausers">
    <thead>
    <tr>
        <th>N°Registro</th><th>Beneficiário</th><th>Data Emissão</th><th>CPF</th><th>CNH</th><th>Data do Cadastro</th></th><th>Operações</th>
    </tr>
    </thead>
    <tbody> 
    <?php
    $data_atual=explode("/" , date('d/m/Y'));
    $ano_atual=$data_atual[2];
    $alvara_vaga_idoso = new alvara_vaga_idoso();
    $alvara_vaga_idoso->selecionaTudo($alvara_vaga_idoso);
    while($res = $alvara_vaga_idoso->retornaDados()):
        echo '<tr>';
        printf('<td>%s</td>',$res->num_registro ."/".$ano_atual);
        printf('<td>%s</td>',$res->nome_beneficiario);
        printf('<td>%s</td>',$res->data_emissao);
        printf('<td>%s</td>',$res->cpf);
        printf('<td>%s</td>',$res->cnh);
        printf('<td class="center">%s</td>',date("d/m/Y - H:i:s",strtotime($res->datacad)));

        printf('<td class="center"><a href="?m=alvara_vaga_idoso&t=incluir_alvaras_vaga_idoso" title="Novo Cadastro"> <img src="images/add.png" alt="Novo Cadastro"/> </a> <a href="?m=alvara_vaga_idoso&t=editar_alvara_vaga_idoso&num_registro=%s" title="Editar Cadastro"> <img src="images/edit.png" alt="Editar Cadastro"/> </a></a> <a href="?m=alvara_vaga_idoso&t=visualizar_alvara_vaga_idoso&num_registro=%s" title="Visualizar Cadastro"> <img src="images/view.png" alt="Visualizar Cadastro"/><a href="?m=alvara_vaga_idoso&t=imprimir_alvara_vaga_idoso&num_registro=%s" title="Imprimir Credencial"> <img src="images/printer.png" alt="Imprimir Credencial"/> </a> </td>',$res->num_registro,$res->num_registro,$res->num_registro);
        echo '</tr>';
    endwhile;
    ?>
    </tbody>
</table>
    
asked by anonymous 02.09.2015 / 20:56

1 answer

2

On% of your page% put

<link rel="stylesheet" href="print.css" media="print" />

Create the head file and style the elements of your table as you need it and give print.css to the elements you do not want to appear on the print page.

Then create a button for printing on your php page:

echo '<a href="#" onClick="print();">Imprimir</a>';

If you prefer to put a separate print page, you can do the same process on it, just change the above php code to:

echo '<script>print();</script>';

And on the print button on the previous page you send the user to this new page. They are two functional forms.

    
02.09.2015 / 21:14