我试图制作一个可以生成报告的PHP页面,但是我一直收到此消息
警告:mysqli_fetch_array()期望参数1为mysqli_result,在第8行的C:\ xampp \ htdocs \ Report.php中给出的布尔值我无法显示数据库中的内容
<?php
function fetch_data()
{
$output = '';
$conn = mysqli_connect("localhost", "root", "", "neo");
$sql = "SELECT * FROM product_order ORDER BY id ASC";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result))
{
$output .= '<tr>
<td>'.$row["odID"].'</td>
<td>'.$row["cusID"].'</td>
<td>'.$row["total"].'</td>
<td>'.$row["or_date"].'</td>
<td>'.$row["or_qty"].'</td>
<td>'.$row["price"].'</td>
</tr>
';
}
return $output;
}
if(isset($_POST["generate_pdf"]))
{
require_once('Tcpdf.php');
$obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$obj_pdf->SetCreator(PDF_CREATOR);
$obj_pdf->SetTitle("Generate HTML Table Data To PDF From MySQL Database Using TCPDF In PHP");
$obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);
$obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$obj_pdf->SetDefaultMonospacedFont('helvetica');
$obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$obj_pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);
$obj_pdf->setPrintHeader(false);
$obj_pdf->setPrintFooter(false);
$obj_pdf->SetAutoPageBreak(TRUE, 10);
$obj_pdf->SetFont('helvetica', '', 11);
$obj_pdf->AddPage();
$content = '';
$content .= '
<h4 align="center">Order Report</h4><br />
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<th width="5%">Customer ID</th>
<th width="30%">Order ID</th>
<th width="15%">Total</th>
<th width="50%">Order date</th>
<th width="75%">Order quantity</th>
<th width="100%">Price</th>
</tr>
';
$content .= fetch_data();
$content .= '</table>';
$obj_pdf->writeHTML($content);
$obj_pdf->Output('file.pdf', 'I');
}
?>