2016-05-12 9 views
0

Wie schreibe ich, wenn Bedingungen innerhalb der TCPDF-Tabelle. Folgendes funktioniert nicht. Wo mache ich Fehler?TCPDF/PHP - wenn Bedingung in der Tabelle nicht funktioniert

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

Antwort

1

Ich bin mir nicht sicher über die tcpdf, aber Sie verwenden die HEREDOC nicht richtig.

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

so was sind Sie wahrscheinlich suchen, ist diese

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