我正在尝试从MySQL数据库获取数据,并使用TCPDF将结果下载为PDF文件。
这是代码:
<?php
require_once('../init.php');
require_once('tcpdf_include.php');
// get booking data
$booking = new Admin;
$letter = new Admin;
$permission = Session::get('logged_permission');
$logged_id = Session::get('logged_id');
$bookingDate = $_GET['bookingDate'];
$bookingEnd = $_GET['bookingEnd'];
if(in_array('all', $permission)) {
$booking->rowQuery("SELECT b.*, a.sid, a.vid, a.did, a.note, a.seatBooked, a.assigned_start, a.assigned_end, a.is_complete FROM booking AS b LEFT JOIN assigned AS a ON b.bid = a.bid WHERE b.bookingDate BETWEEN $bookingDate AND $bookingEnd GROUP BY a.bid ");
} else {
$logged_id = Session::get('logged_id');
$booking->rowQuery("SELECT b.*, a.sid, a.vid, a.did, a.note, a.seatBooked, a.assigned_start, a.assigned_end, a.is_complete FROM booking AS b LEFT JOIN assigned AS a ON b.bid = a.bid WHEREb.bookingDate BETWEEN $bookingDate AND $bookingEnd AND b.a_id = $logged_id GROUP BY a.bid ");
}
$numRows = $booking->rows;
$data = $booking->result->fetch_assoc();
// some more code to get the each column value
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 048');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 048', PDF_HEADER_STRING);
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
$pdf->SetFont('helvetica', 'B', 20);
$pdf->AddPage();
$pdf->Write(0, 'Example of HTML tables', '', 0, 'L', true, 0, false, false, 0);
$pdf->SetFont('helvetica', '', 8);
$html = 'Demo Data';
$pdf->writeHTML($html, true, false, false, false, '');
//Close and output PDF document
ob_clean();
ob_flush();
$pdf->Output( substr(md5(mt_rand()), 0, 7).'.pdf', 'I');
ob_end_flush();
ob_end_clean();
现在,如果我使用此行,它将始终显示无法加载PDF文档:
$data = $booking->result->fetch_assoc();
您知道我需要运行此行才能从MySQL数据库获取数据。
但是如果没有此行,它将下载/显示带有演示数据的PDF文件
你们能告诉我为什么我会遇到这种错误吗?