我有一个关于在PHP变量中集成PHP代码的问题。 我正在为PHP做PDF报告,我正在使用PHP到PDF
我想从ORACLE DB查询表格并将其打印成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中工作。我是否与逃脱角色犯了错误? 谢谢你的帮助
答案 0 :(得分: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 :(得分: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>";
答案 2 :(得分: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>';
答案 3 :(得分: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,您将只看到代码而不是其他任何内容。