简体   繁体   English

如何在PHP中将HTML表作为TCPDF对象插入?

[英]How to insert HTML table as TCPDF Object in PHP?

I am trying to get a table in PDF downloadable, but the problem is I am using selection statements with loops for retrieving data. 我正在尝试获取可下载的PDF表,但问题是我正在使用带有循环的选择语句来检索数据。 The table is working fine without loops. 该表工作正常,没有循环。

I have gone through these examples https://tcpdf.org/examples/ and getting problem when retrieve data by loops. 我已经遍历了这些示例https://tcpdf.org/examples/,并在通过循环检索数据时遇到问题。

This is the table I want to pass from template to $html variable(PDF object): 这是我要从模板传递到$ html变量(PDF对象)的表:

<h2 align ="center" bgcolor ="#75777a">Order Pick List</h2>
<table>
<tr>
<th>Col 1</th>
<th>Col 2</th>
<th>Col 3</th>
<th>Col 4</th>
</tr>
<?php $Orders= $block->getOrders();
foreach ($Orders as $order) {
    $Colone = $order->getID();
    $Coltwo = $order->getName();
    $items = $order->getitems();?>

    <tr>
        <td><?php echo $Colone; ?></td>
        <td><?php echo $Coltwo; ?></td>

        <?php foreach ($items as $item ) {
            $itemName = $item->getitemName();?>

            <td>
                <?php echo $itemName; ?>
            </td>

        <?php } ?>
    </tr>

<?php}
?>

Has anyone done anything similar they wish to share to get me started? 有没有人做过他们想分享的类似事情以帮助我入门?

Try to solve your problem in this way 尝试以这种方式解决您的问题

public function getHtml()
{
$html = '';
$tempItem1 = '';
$tempitemQuantity = '';
$html = '<h1 bgcolor ="#75777a" align = "center">Order Pick List</h1>';
$html.= '<table border= "1">';
$html.= '<tr>
<th><b>Col 1</b></th>
<th><b>Col 2</b></th>
<th><b>Col 3</b></th>
<th><b>Col 4</b></th>
</tr>';
$_data = $this->order->getOrders();
foreach ($_data as $value){
$tempItem1 = '';
$tempitemQuantity = '';
$OrderId = $value->getEntityId();;
$tempName1= $value->getCustomerName();
$OrderItems = $value->getAllItems();
foreach ($OrderItems as $item) {
$tempitemQuantity.= $item->getQtyOrdered().'<br />';
$tempItem1.= $item->getName().'<br />';
}
$html.='<tr>
<td>'.$OrderId.'</td>
<td>'.$tempName1.'</td>
<td>'.$tempItem1.'</td>
<td>'.$tempitemQuantity.'</td>
</tr>';
}
$html.='</table>';
return $html;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM