2014-09-11 72 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>';