1
I am generating a PDF with database data and the code it is running correctly.
Behold:
<?php
include_once '../controller/ClienteController.php';
include_once '../controller/LocacaoController.php';
include_once 'mpdf/mpdf.php';
$cc = new ClienteController();
$cliente = $cc->listaClienteId($_REQUEST['id']);
$endereco = $cliente->getEndereco();
$telefones = $cliente->getTelefones();
$telefone1 = $telefones[0];
$telefone2 = $telefones[1];
$nomeCliente = $cliente->getNome();
$cpf = $cliente->getCpf();
$tel1 = $telefone1;
$tel2 = $cc->validaTelefone($telefone2);
$cidade = $endereco->getCidade();
$rua = $endereco->getRua();
$numero = $endereco->getNumero();
$lc = new LocacaoController();
$objetos = $lc->listaLocacoesFitaId($_REQUEST['id']);
$locacao = $objetos[0];
$cliente = $locacao->cliente();
$filme = $locacao->midia();
$valor = "R$" . number_format($locacao->getValor(), 2);
$multa = "R$" . number_format($locacao->getMulta(), 2);
$dataL = $locacao->getDataLocacao();
$dataE = $locacao->getDataEntrega();
$pagina ="
<html>
<body>
<h1>Vintage Locadora</h1>
<h2>Histórico de Locações de Clientes</h2>
<h3>Dados do Cliente</h3>
<table>
<tr>
<th>Nome</th>
<th>CPF</th>
<th>Telefone 1</th>
<th>Telefone 2</th>
<th>Cidade</th>
<th>Rua</th>
<th>Numero</th>
</tr>
<tr>
<td>$nomeCliente</td>
<td>$cpf</td>
<td>$tel1</td>
<td>$tel2</td>
<td>$cidade</td>
<td>$rua</td>
<td>$numero</td>
</tr>
</table>
<h3>Histórico de Locações de Fita</h3>
<table>
<tr>
<th>Nome do Cliente</th>
<th>Filme Locado</th>
<th>Valor da Locação</th>
<th>Multa</th>
<th>Data da Locação</th>
<th>Data de Entrega</th>
</tr>
<tr>
<td>$cliente</td>
<td>$filme</td>
<td>$valor</td>
<td>$multa</td>
<td>$dataL</td>
<td>$dataE</td>
</tr>
</table>
</body>
</html>
";
$arquivo ='vintage.pdf';
$pdf = new mPDF();
$css = file_get_contents('css/historico-estilo.css');
$pdf->WriteHTML($css, 1);
$pdf->WriteHTML($pagina);
$pdf->Output($arquivo, 'I');
?>
The problem is, on the lines of code:
$objetos = $lc->listaLocacoesFitaId($_REQUEST['id']);
$locacao = $objetos[0];
If you return more than one object, how will I create the new rows in the table? Because with only one object I already define within the string $pagina
lines with the values of the object, now returning more than one object, I have to create dynamic lines for the table.
Have you tried to implement any loop loop that generates the table for all records?
– Woss
@Andersoncarloswoss as well ? has to give me an example
– Rodrigo Jacinto