TCPDF只打印最后一行

时间:2014-02-20 09:32:24

标签: php mysql tcpdf

以下代码仅打印最后一行,当我尝试回显表时,它给了我所有的行,但pdf只给出了最后一行。请帮忙

$tbl1 = '<table cellpadding="3" cellspacing="1" width="100%" style="text-align:center;" border="1">
<tr style="font-weight:500;">
<td height="35">Deal Id</td>
<td>Deal Title</td>
<td>Deal Offer Id </td>
<td>No. Of Purchases</td>
<td>Quantity</td>
<td>Total Price</td>
<td>Date</td>
</tr>';
while($mwor_res1=mysql_fetch_array($mwor_qry5)){
    $tbl1.='<tr style="align="center">
    <td>'.$mwor_res1['deal_id'].'</td>
    <td>'.$mwor_res1['title'].'</td>
    <td>'.$mwor_res1['deal_offer_id'].'</td>
    <td>'.$mwor_res1['count( ord_dt.deal_offer_id )'].'</td>
    <td>'.$mwor_res1['sum( ord_dt.quantity )'].'</td>
    <td>'.$mwor_res1['sum( ord_dt.total_price )'].'</td>
    <td>'.$mwor_res1['order_date'].'</td>
    </tr>';
}
$tbl1.='</table>';

    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

    $pdf->AddPage();
    $pdf->writeHTML($tbl1, true, 0, true, 0);
    $pdf->lastPage();
    $pdf->Output('Deal-wise-report.pdf', 'D');

2 个答案:

答案 0 :(得分:0)

似乎你在打印前将指针设置到最后一页:

$pdf->lastPage();

您桌子的其余部分可能在第一页。

您可能希望打印所有页面或调整页面设置以使其适合一页。

答案 1 :(得分:0)

尝试使用ob_start(),使用此代码

<?php
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->AddPage();
    ob_start();
?>
<table cellpadding="3" cellspacing="1" width="100%" style="text-align:center;" border="1">
    <tr style="font-weight:500;">
        <td height="35" align="center">Deal Id</td>
        <td align="center">Deal Title</td>
        <td align="center">Deal Offer Id </td>
        <td align="center">No. Of Purchases</td>
        <td align="center">Quantity</td>
        <td align="center">Total Price</td>
        <td align="center">Date</td>
    </tr>
<?php
    while($mwor_res1=mysql_fetch_array($mwor_qry5))
    {
?>
    <tr>
        <td align="center"><?php echo $mwor_res1['deal_id']; ?></td>
        <td align="center"><?php echo $mwor_res1['title']; ?></td>
        <td align="center"><?php echo $mwor_res1['deal_offer_id']; ?></td>
        <td align="center"><?php echo $mwor_res1['count( ord_dt.deal_offer_id )']; ?></td>
        <td align="center"><?php echo $mwor_res1['sum( ord_dt.quantity )']; ?></td>
        <td align="center"><?php echo $mwor_res1['sum( ord_dt.total_price )']; ?></td>
        <td align="center"><?php echo $mwor_res1['order_date']; ?></td>
    </tr>
<?php
    }
?>
</table>
<?php
    $tbl1 = ob_get_contents();
    ob_end_clean();
    $pdf->writeHTML($tbl1, true, false, true, false, '');
    $pdf->Output('Deal-wise-report.pdf', 'D');
?>