簡體   English   中英

PHP DOMPDF 在我的數據庫中顯示表

[英]PHP DOMPDF display table in my db

我是 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));

?>

我試圖仔細檢查每個拼寫和語法,但我認為它是正確的。 它不顯示行,但顯示表的標題。

尋求幫助。 提前致謝。

嘗試更新 while($row = mysqli_fetch_array($result))

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

希望它有幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM