我是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));
?>
我试图仔细检查每个拼写和语法,但我认为它是正确的。它不显示行,但显示表的标题。
寻求帮助。预先感谢。
尝试尝试同时更新($ row = mysqli_fetch_array($ result))
使用while($ row = mysqli_fetch_array($ result,MYSQLI_ASSOC))
希望有帮助
尝试尝试同时更新($ row = mysqli_fetch_array($ result))
使用while($ row = mysqli_fetch_array($ result,MYSQLI_ASSOC))
希望有帮助