【发布时间】:2018-02-10 08:55:12
【问题描述】:
我是 DOMPDF 的新手,我正在尝试使用 dompdf 将我表中未归档的所有记录打印为 pdf。这是以pdf格式打印html的代码。
<?php
// include autoloader
require_once('../autoload.inc.php');
// Reference the dompdf namespace
use Dompdf\Dompdf;
$dompdf = new Dompdf();
include("../config.php");
$tbl_name = "patients";
$sql = "SELECT * FROM $tbl_name WHERE archive = 1";
$result = mysqli_query($connection, $sql);
$total = mysqli_num_rows($result);
$html = "
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #black;
text-align: left;
}
</style>
<h4>
Total no. of preschooler '.$total.'
</h4>
<table>
<tr>
<th>ID</th>
<th>Last Name</th>
<th>First Name</th>
<th>Gender</th>
<th>Age</th>
<th>Weight (kg)</th>
<th>Height (cm)</th>
<th>Nutritional Status</th>
<th>Barangay</th>
</tr>
";
while($row = mysqli_fetch_array($result))
{
$html .= '
<tr>
<td>'.$row["p_id"].'</td>
<td>'.$row["last_name"].'</td>
<td>'.$row["first_name"].'</td>
<td>'.$row["Gender"].'</td>
<td>'.$row["last_name"].'</td>
<td>'.$row["Years"].'</td>
<td>'.$row["wt"].'</td>
<td>'.$row["ht"].'</td>
<td>'.$row["interp"].'</td>
<td>$'.$row["barangay"].'</td>
</tr>
';
}
$html .= '</table>';
$dompdf->loadHtml($html);
$dompdf->setPaper('A4', 'landscape');
$dompdf->render();
// Output
$dompdf->stream('coderworld',array('Attachment'=>0));
?>
我尝试仔细检查每个拼写和语法,但我认为它是正确的。它不显示行,但显示表格的标题。
寻求帮助。 提前致谢。
【问题讨论】:
-
这个总编号。学龄前儿童 '.$total.'应该是总数。学龄前儿童的“.$total”。 (用双引号代替单引号)然后看看会发生什么。
-
请回显 $html 并验证它不应有任何注释代码和错误的未关闭标签。
-
我更改了 '.$total.'到“.$total”。它没有显示任何东西。 @Naincy 我试图回应它,但它说无法加载 pdf 文档。
-
请回显 $html 并退出并分享该 html
-
我收到一个错误,其中 PHP 解析错误:语法错误,意外的 '"',在 /var/www/html/NutriCareOLD/ 中需要标识符 (T_STRING) 或变量 (T_VARIABLE) 或数字 (T_NUM_STRING)第 55 行的 admin/try.php。顺便说一句,当我 var 转储 $total 和 $result 时,它总是给我 null