Paulo Jorge Posted May 28, 2012 at 08:40 PM Report #458668 Posted May 28, 2012 at 08:40 PM Boa noite gostava de criar um pdf com 2 tabelas, cujo os valores estão na minha base de dados. Uma para fazer o cabeçalho da factura onde pretendo colocar o numero da encomenda, o nome do cliente e a data . E outra para o corpo onde pretendo colocar o nome de produto, a quantidade, o preço, o iva, e o total. Alguém me pode dar uma ajuda de como fazer as tabelas ? eu ja tive a pesquisar mas todas elas estão a dar erros e não estou a conseguir corrigir
Ricardo Gonçalves Posted May 28, 2012 at 08:55 PM Report #458677 Posted May 28, 2012 at 08:55 PM para bucares dados á base de dados tens de fazer uma ligação da tua página á BD, depois fazes um SELECT da tabela que pretendes e depois com os nomes que tens na BD imprimes. comp por exemplo crias a tabela em php e uma das células é assim : <?php echo'<table>'; echo'<tr>'; echo '<td>'.$preco.'</td>'; echo'</tr>'; echo'</table>'; ?> cumps, Ricardo Gonçalves
johnmaia Posted May 28, 2012 at 09:03 PM Report #458680 Posted May 28, 2012 at 09:03 PM (edited) Boa noite gostava de criar um pdf com 2 tabelas, cujo os valores estão na minha base de dados. Uma para fazer o cabeçalho da factura onde pretendo colocar o numero da encomenda, o nome do cliente e a data . E outra para o corpo onde pretendo colocar o nome de produto, a quantidade, o preço, o iva, e o total. Alguém me pode dar uma ajuda de como fazer as tabelas ? eu ja tive a pesquisar mas todas elas estão a dar erros e não estou a conseguir corrigir Se realmente pretendes gerar PDFs com PHP sugiro que leias a documentação de uma das seguintes class: TCPDF ou FPDF Edited May 28, 2012 at 09:03 PM by johnmaia 1 Report
Ricardo Gonçalves Posted May 28, 2012 at 09:11 PM Report #458684 Posted May 28, 2012 at 09:11 PM para fazer pdf prefiro TCPPF acho que é o mais completo.
Paulo Jorge Posted May 29, 2012 at 08:08 AM Author Report #458765 Posted May 29, 2012 at 08:08 AM (edited) Estou a fazer como disseste e está tudo a dar certo só menos uma coisa. Eu fiz este código para apresentar no pdf a nota de encomenda só que a tabela total está a dar errada não consigo por ou no final da tabela, ou sem ela se repetir. // ----------------------------------------------------------------------------- $tbl_header = '<style> table { border-collapse: collapse; border-spacing: 0; margin: 0 20px; } tr { padding: 3px 0; } th { background-color: #CCCCCC; border: 1px solid #DDDDDD; color: #333333; font-family: trebuchet MS; font-size: 30px; padding-bottom: 4px; padding-left: 6px; padding-top: 5px; text-align: left; } td { border: 1px solid #CCCCCC; font-size: 25px; padding: 3px 7px 2px; } </style> <table width="600" cellspacing="2" cellpadding="1" border="0"> <tr style="background-color:#FF0000;color:#FFFF00;"> <th><font face="Arial, Helvetica, sans-serif">Produto</font></th> <th><font face="Arial, Helvetica, sans-serif">Preco</font></th> <th><font face="Arial, Helvetica, sans-serif">Quantidade</font></th> <th><font face="Arial, Helvetica, sans-serif">SubTotal</font></th> </tr> <table width="600" cellspacing="2" cellpadding="1" border="0"> <tr> <td colspan="3"><div align="right"><strong>TOTAL:</strong> </div> <div align="right"></div> <div align="right"></div></td> <td><div align="center" class="style3 style4">'.number_format($soma_carrinho,2,",",".").'</div></td> </tr>'; $tbl_footer = '</table></table>'; $tbl = ''; $sql_meu_carrinho11 = "SELECT * FROM carrinho WHERE sessao = '".session_id()."' ORDER BY nome ASC"; $exec_meu_carrinho11 = mysql_query($sql_meu_carrinho11, $conexao) or die(mysql_error()); $qtd_meu_carrinho11 = mysql_num_rows($exec_meu_carrinho11); while ($row_meu_carrinho11 = mysql_fetch_assoc($exec_meu_carrinho11)) { $soma_carrinho += ($row_meu_carrinho11['Preco']*$row_meu_carrinho11['qtd']); $tbl .= ' <tr> <td>'.$row_meu_carrinho11['nome'].'</td> <td>'.number_format($row_meu_carrinho11['Preco'],2,",",".").'</td> <td>'.$row_meu_carrinho11['qtd'].'</td> <td>'.number_format($row_meu_carrinho11['Preco']*$row_meu_carrinho11['qtd'],2,",",".").'</td> </tr> '; } // output the HTML content $pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '') //----------------------------------------------------------------------------- Edited May 29, 2012 at 07:11 PM by scorch Adicionado Geshi.
johnmaia Posted May 29, 2012 at 09:06 AM Report #458771 Posted May 29, 2012 at 09:06 AM Experimenta assim: $html = ' <style> table { border-collapse: collapse; border-spacing: 0; margin: 0 20px; } tr { padding: 3px 0; } th { background-color: #CCCCCC; border: 1px solid #DDDDDD; color: #333333; font-family: trebuchet MS; font-size: 30px; padding-bottom: 4px; padding-left: 6px; padding-top: 5px; text-align: left; } td { border: 1px solid #CCCCCC; font-size: 25px; padding: 3px 7px 2px; } </style> <table width="600" cellspacing="2" cellpadding="1" border="0"> <tr style="background-color:#FF0000;color:#FFFF00;"> <th><font face="Arial, Helvetica, sans-serif">Produto</font></th> <th><font face="Arial, Helvetica, sans-serif">Preco</font></th> <th><font face="Arial, Helvetica, sans-serif">Quantidade</font></th> <th><font face="Arial, Helvetica, sans-serif">SubTotal</font></th> </tr>'; $sql_meu_carrinho11 = "SELECT * FROM carrinho WHERE sessao = '".session_id()."' ORDER BY nome ASC"; $exec_meu_carrinho11 = mysql_query($sql_meu_carrinho11, $conexao) or die(mysql_error()); $qtd_meu_carrinho11 = mysql_num_rows($exec_meu_carrinho11); while ($row_meu_carrinho11 = mysql_fetch_assoc($exec_meu_carrinho11)) { $soma_carrinho += ($row_meu_carrinho11['Preco']*$row_meu_carrinho11['qtd']); $html .= ' <tr> <td>'.$row_meu_carrinho11['nome'].'</td> <td>'.number_format($row_meu_carrinho11['Preco'],2,",",".").'</td> <td>'.$row_meu_carrinho11['qtd'].'</td> <td>'.number_format($row_meu_carrinho11['Preco']*$row_meu_carrinho11['qtd'],2,",",".").'</td> </tr>'; } $hmtl .= '</table>'; $html .=' <table width="600" cellspacing="2" cellpadding="1" border="0"> <tr> <td colspan="3"><div align="right"><strong>TOTAL:</strong> </div> <div align="right"></div> <div align="right"></div></td> <td><div align="center" class="style3 style4">'.number_format($soma_carrinho,2,",",".").'</div></td> </tr> </table>'; $pdf->writeHTML($html, true, false, false, false, ''); 1 Report
Paulo Jorge Posted May 29, 2012 at 06:08 PM Author Report #458980 Posted May 29, 2012 at 06:08 PM Ficou muito bem muito obrigada 😄
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now