TCPDF / PHP - 如果表中的条件不起作用

时间:2016-05-12 13:43:43

标签: php tcpdf

如果TCPDF表中的条件如何写入。以下不起作用。我在哪里做错了?

$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, '');

1 个答案:

答案 0 :(得分:1)

我不确定tcpdf,但你没有正确使用HEREDOC。

$insertedVar = 'abc';
$var = <<<EOD
    here's some text, quotes "'
    and variable $interterdVar
EOD;

所以你可能正在寻找的是

<?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;