2012-07-19 62 views
6

我有一个表在数据库这样如何在TCPDF中使用PHP脚本?

expedition_name | Phone | CP | 
__________________________________________ 
    Starsindo | 09890 | John | 
    Iron Bird | 09891 | Gina | 
    MSA Cargo | 09890 | John | 

现在我将创建该表使用HTML功能TCPDF的PDF。

,但我仍然混淆如何组合这 我这样的代码

<?php 

require_once('tcpdf/config/lang/eng.php'); 
require_once('tcpdf/tcpdf.php'); 

// create new PDF document 
include "koneksi.php"; 
    $sql = "SELECT * FROM tb_exp_local"; 
    $hasil = mysql_query($sql); 
    $data = mysql_fetch_array($hasil); 

    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); 

    // set font 
    $pdf->SetFont('times', '', 11); 

    // add a page 
    $pdf->AddPage(); 



    $html = '<h2>List Of Expediton</h2> //Title 
<table border="1" cellspacing="3" cellpadding="4"> 
    <tr> 
     <th>Expedition</th>    //head of column name 
     <th align="center">Phoine</th> //head of column name 
     <th align="center">CP</th>  //head of column name 
    </tr> 
    while($data=mysql_fetch_array($hasil)) 
    { 
    <tr> 
     <td>$data[nama_exp]</td> 
    </tr> 
    } 
</table>'; 


    $pdf->writeHTML($html, true, false, true, false, ''); 


    $pdf->Output('Local Expedition, 'I'); 

?> 

谁能帮助我,如何解决呢?并且数据可以用PDF写入?

+0

,什么是错误/问题? – k102 2012-07-19 08:47:38

回答

7

你需要的东西,如准备好你的html:

$html = '<h2>List Of Expediton</h2> //Title 
    <table border="1" cellspacing="3" cellpadding="4"> 
    <tr> 
     <th>Expedition</th>    //head of column name 
     <th align="center">Phoine</th> //head of column name 
     <th align="center">CP</th>  //head of column name 
    </tr>'; 

while($data=mysql_fetch_array($hasil)) { 
    $html .= '<tr><td>'.$data['nama_exp'].'</td></tr>'; 
} 
$html .= '</table>'; 
+0

+1为你的答案伙计.... – mrsrinivas 2012-07-19 09:03:37