2

我有一个关于 TCPDF 的问题,我试图从我的数据库中输出数据并循环它们我尝试按照此处给出的答案TCPDF - 从 mysql 打印表, 但它没有正确显示我的数据库的内容,例如假设的输出是:1 2 3 4 5

但发生的是 1 q a 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');

?>

提前致谢

4

0 回答 0