douju8113 2016-05-12 13:43
浏览 49

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

How to write if conditions inside TCPDF table. 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, '');
  • 写回答

1条回答 默认 最新

  • dongrong7883 2016-05-12 14:06
    关注

    I'm not sure about the tcpdf, but you're not using the HEREDOC properly.

    $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;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)