TCPDF - 无法将MySQL内容显示为PDF格式

时间:2015-10-25 13:58:37

标签: php html mysql while-loop tcpdf

我正在尝试制作产品目录的可打印版本。如果我用HTML显示产品,它可以正常工作。但是当我尝试使用TCPDF时,我松了一半或根本没有。

$query = "SELECT ID, Category_Name, Image FROM Categories ORDER BY Position ASC";
$result = mysqli_query($connection, $query);
confirm_query($result);

while ($cat = mysqli_fetch_row($result)) {
    // add a page
    $pdf->AddPage();

    $query1 = "SELECT * FROM Products WHERE Category = " . $cat[0] . " AND Visibility = 1 ORDER BY Product_Name ASC";
    $result1 = mysqli_query($connection, $query1);
    $html = $query1;
    confirm_query($result1);

    //$html .= '<style>'. file_get_contents('./images/print.css').'</style>';

    $html .= '<table style="margin: 0 auto;"><tbody>';
    $html .= '<tr><th colspan="6"><div id="title" style="color: white;">' . $cat[1] . '</div></th></tr>';
    $html .= '<tr>';
    $html .= '<th></th>';
    $html .= '<th>Product</th>';
    $html .= '<th>Pack Size</th>';
    $html .= '<th>Price(Ex VAT)</th>';
    $html .= '<th>Price(Inc)</th>';
    $html .= '<th>RRP</th>';
    $html .= '</tr>';

    // Show product prodcuts from selected category
    while ( $row123 = mysqli_fetch_row($result1)) {
        $html .= '<tr><td>';
        $html .= '<img width="100px" height="100px" src="/images/' . $row123[6] . '"/>';
        $html .= '</td><td>';
        $html .= '<b><u>' . $row123[1] . '</u></b><br /><i>' . $row123[5] . '</i>';
        $html .= '</td><td>';
        $html .= $row123[3];
        $html .= '</td><td>';
        $html .= '£' . $row123[4];
        //echo '<br />';
        $html .= '</td><td>';
        $query2 = "SELECT VAT FROM VAT WHERE ID = " . $row123[7];
        $result2 = mysqli_query($connection, $query2);
        confirm_query($result2);

        // Put results in an accessible form
        $result_array2 = array();
        while ($row234 = mysqli_fetch_row($result2)) {$result_array2[] = $row234;}

        $html .= '£' . number_format($row123[4] + ($result_array2[0][0] * $row123[4] / 100), 2, '.', '');
        $html .= '</td><td>';
        if ($row123[9] == "") {
            $html .= "N/A";
        } else {
            $html .= '£' . number_format($row123[9], 2, '.', '');   
        }
        $html .= '</td>';
        $html .='</tr>';
    }
    $html .= '</tbody></table>';


// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
}

如果我注释掉第二个while循环,我可以得到第一个查询($ query1)来回显。每个类别每页一个。但是当我取消注释它时,它只会创建4个空白页。

0 个答案:

没有答案