TCPDF以及如何使用循环从数据库输出文件

时间:2012-09-24 23:34:47

标签: php mysql tcpdf

我对TCPDF有疑问 我试图从我的数据库输出数据并循环它们 我试着按照这里给出的答案TCPDF - printing table from mysql 但它没有正确显示我的数据库的内容 例如,假定的输出是: 1 2 3 4 5

但是会发生什么 1 q 一个 w ^ 4

这是我的代码

  <?php
include('connect.php');
    require_once('libraries/tcpdf/config/lang/eng.php');
    require_once('libraries/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set default font subsetting mode
$pdf->setFontSubsetting(true);

// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);

// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();

// set text shadow effect
$pdf->setTextShadow(array('enabled'=>true, 'depth_w'=>0.2, 'depth_h'=>0.2, 'color'=>array(196,196,196), 'opacity'=>1, 'blend_mode'=>'Normal'));


$query=mysql_query("select * from ci");
$query=mysql_fetch_assoc($query);

$tbl_header = '<table style="width: 638px;" cellspacing="0">';
$tbl_footer = '</table>';
$tbl = '';

foreach($query as $query2){
$ciid = $query2['ci_id'];
$cinature = $query2['ci_nature'];
$ciposition = $query2['ci_postion'];
$tbl .= '
    <tr>
        <td style="border: 1px solid #000000; width: 150px;">'.$ciid.'</td>
        <td style="border: 1px solid #000000; width: 378px;">'.$cinature.'</td>
        <td style="border: 1px solid #000000; width: 110px; text-align:center">'.$ciposition.'</td>
    </tr>
';}

$pdf->writeHTML($tbl_header . $tbl . $tbl_footer, true, false, false, false, '');


$pdf->Output('test.pdf');

?>

提前致谢

0 个答案:

没有答案