2014-09-11 71 views
0

我有一个关于在PHP变量中集成PHP代码的问题。 我做报告PHP为PDF格式,我使用PHP为PDFPHP内部的PHP代码变量

我想从ORACLE数据库查询表并打印到PDF,现在我有转义字符和东西

我的代码问题是这样的,

$compProfileSql = "SELECT * FROM DRAWING WHERE PROJECT_NAME = :PROJNAME" 
$compProfileParse = oci_parse($conn, $compProfileSql); 
         oci_bind_by_name($compProfileParse, ":PROJNAME", $_SESSION['cd-dropdown']); 
         oci_execute($compProfileParse); 

$content = " 
<table class=\"table table-bordered\"> 
       <thead> 
        <tr> 
         <th>PROJECT NAME</th> 
         <th>COMPONENT</th> 
         <th>DRAWING</th>       
        </tr> 
       </thead> 
       <tbody>    
        while (($row = oci_fetch_array($compProfileParse, OCI_BOTH)) != false){ 
         <tr> 
          <td>$row[COMP_TYPE]</td> 
          <td>$row[JML_DWG]</td> 
          <td>$row[JML_MARKING]</td>                  
         </tr> 
        } 
       </tbody> 
      </table> 
"; 

我看不出在生成的PDF中工作的表。我是否犯了转义字符? 感谢您的帮助

回答

1

你需要单独它:

$content = " 
<table class=\"table table-bordered\"> 
      <thead> 
       <tr> 
        <th>PROJECT NAME</th> 
        <th>COMPONENT</th> 
        <th>DRAWING</th>       
       </tr> 
      </thead> 
      <tbody>";    
       while (($row = oci_fetch_array($compProfileParse, OCI_BOTH)) != false){ 
        $content .= "<tr> 
         <td>" . $row['COMP_TYPE'] . "</td> 
         <td>" . $row['JML_DWG'] . "</td> 
         <td>" . $row['JML_MARKING'] . "</td>                  
        </tr>"; 
       } 
      $content .= "</tbody> 
     </table>"; 
0

想补充一点的评论,但你不会看到太多的,所以......

我可以先告诉的是,你不区分HTML和PHP,尝试这样的:

$content = " 
<table class=\"table table-bordered\"> 
      <thead> 
       <tr> 
        <th>PROJECT NAME</th> 
        <th>COMPONENT</th> 
        <th>DRAWING</th>       
       </tr> 
      </thead> 
      <tbody> <?php    
       while (($row = oci_fetch_array($compProfileParse, OCI_BOTH)) != false){ ?> 
        <tr> 
         <td><?php echo $row[COMP_TYPE]; ?></td> 
         <td><?php echo $row[JML_DWG]; ?></td> 
         <td><?php echo $row[JML_MARKING]; ?></td>                  
        </tr> 
       <?php } ?> 
      </tbody> 
     </table>"; 

虽然我不知道你正在使用打印到PHP的方法,如果这将被视为一个简单的字符串,而不是转换到任何地方HTML,你只会看到代码,没有别的。

1

,你也可以写如下,

$content = " 
     <table class=\"table table-bordered\"> 
      <thead> 
       <tr> 
        <th>PROJECT NAME</th> 
        <th>COMPONENT</th> 
        <th>DRAWING</th>       
       </tr> 
      </thead> 
      <tbody>";    
       while (($row = oci_fetch_array($compProfileParse, OCI_BOTH)) != false){ 
        $content .= "<tr> 
         <td>$row[COMP_TYPE]</td> 
         <td>$row[JML_DWG]</td> 
         <td>$row[JML_MARKING]</td>                  
        </tr>"; 
       } 
      $content .= "</tbody> 
     </table> 
"; 
1

您可以使用单引号代替双qoutes然后再使用转义字符,你将不需要。

$content = ' 
    <table class="table table-bordered"> 
        <thead> 
         <tr> 
          <th>PROJECT NAME</th> 
          <th>COMPONENT</th> 
          <th>DRAWING</th>       
         </tr> 
        </thead> 
        <tbody>';  

        while (($row = oci_fetch_array($compProfileParse, OCI_BOTH)) != false){ 
        $content.= '<tr> 
           <td>'.$row["COMP_TYPE"].'</td> 
           <td>'.$row["JML_DWG"].'</td> 
           <td>'.$row["JML_MARKING"].'</td>    
          </tr>'; 
         } 
        $content.= '</tbody> 
        </table>';