简体   繁体   English

PHP DOMPDF 在我的数据库中显示表

[英]PHP DOMPDF display table in my db

I am new to DOMPDF and I am trying to print to pdf using dompdf all the records that is unarchive in my table.我是 DOMPDF 的新手,我正在尝试使用 dompdf 将表中未归档的所有记录打印为 pdf。 This is the code to print the html in 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));

?>

I tried to check each spelling and syntax carefully but I think its correct.我试图仔细检查每个拼写和语法,但我认为它是正确的。 It do not display the rows but it displays the heading of the table.它不显示行,但显示表的标题。

Looking for help.寻求帮助。 Thanks in advance.提前致谢。

Try updating while($row = mysqli_fetch_array($result))尝试更新 while($row = mysqli_fetch_array($result))

With while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))用 while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))

Hope it helps希望它有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM