[英]TCPDF/PHP - if condition inside table is not working
How to write if conditions inside TCPDF table. 如何在TCPDF表中写入条件。 The following is not working. 以下内容不起作用。 Where am I doing mistake? 我在哪里做错了?
$tbl = '<<<EOD
<style>
td {
text-align: center;
}
</style>
<table cellpadding="1" cellspacing="0" border="1">
<thead style="text-align:center">
<tr style="background-color:#FFFF00;color:#0000FF;text-align:center">
<th>Discounts</th>
<th>%</th>
</tr>
</thead>
<tbody>
<tr>
<th>Corporate</th>
<td>$corporateDiscount</td>
</tr>
<tr>
<th>Negotiated Discount</th>
<td>$negotiatedDiscountPrint</td>
</tr>';
if($mag == 'Axon') {
$tbl .= '<tr>
<th>New Discount</th>
<td>$newList</td>
</tr>';
}
$tbl .= '<tr>
<th style="color:#0000FF;">Total Discount</th>
<td>$secondTableTotalPrint</td>
</tr>
</tbody>
</table>
EOD';
$pdf->writeHTML($tbl, true, false, false, false, '');
I'm not sure about the tcpdf, but you're not using the HEREDOC properly. 我不确定tcpdf,但您没有正确使用HEREDOC。
$insertedVar = 'abc';
$var = <<<EOD
here's some text, quotes "'
and variable $interterdVar
EOD;
so what you're probably looking for is this 所以您可能正在寻找的是
<?php
$corporateDiscount = "10";
$negotiatedDiscountPrint = "5";
$newList = "20";
$secondTableTotalPrint = "30";
$mag = 'Axon';
$tbl = <<<EOD
<style>
td {
text-align: center;
}
</style>
<table cellpadding="1" cellspacing="0" border="1">
<thead style="text-align:center">
<tr style="background-color:#FFFF00;color:#0000FF;text-align:center">
<th>Discounts</th>
<th>%</th>
</tr>
</thead>
<tbody>
<tr>
<th>Corporate</th>
<td>$corporateDiscount</td>
</tr>
<tr>
<th>Negotiated Discount</th>
<td>$negotiatedDiscountPrint</td>
</tr>
EOD;
if($mag == 'Axon') {
$tbl .= "<tr>
<th>New Discount</th>
<td>$newList</td>
</tr>";
}
$tbl .= "<tr>
<th style=\"color:#0000FF;\">Total Discount</th>
<td>$secondTableTotalPrint</td>
</tr>
</tbody>
</table>";
echo $tbl . PHP_EOL;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.