我尝试使用mysql
将tcpdf
表打印到PDF,但输出只是空白(除了页眉和页脚)。我正在做的是返回fetchdata()
函数中的所有内容。我究竟做错了什么?我不明白为什么表没有输出,因为它可以输出页眉和页脚到PDF。非常感谢您的帮助。
<?php
session_start();
$date= $_SESSION["date"];
function fetchdata($date)
{
$output='';
$output .= "<p>" . date_format($date, "F j, Y") . " Payroll Report</p>";
$output .= "<table>";
$output .= "<th>Employee Name</th>";
$output .= "<th>Basic Pay</th>";
$output .= "<th>Rate/Day</th>";
$output .= "<th>Rate/Hour</th>";
$output .= "<th>Overtime</th>";
$output .= "<th>Allowance</th>";
$output .= "<th>Commissions</th>";
$output .= "<th>Housing Fee</th>";
$output .= "<th>Cash Advances</th>";
$output .= "<th>Loans</th>";
$output .= "<th>Coop Share</th>";
$output .= "<th>SSS</th>";
$output .= "<th>Philhealth</th>";
$output .= "<th>Pagibig</th>";
$output .= "<th>Personal Gas</th>";
$output .= "<th>Absences</th>";
$output .= "<th>Withholding Tax</th>";
$output .= "<th>Salary Differential</th>";
$output .= "<th>Total</th>";
$output .= "<tr>";
require('functions.php');
require('connecttoserver.php');
$sql = 'SELECT * FROM employees ORDER BY employee_id ASC';
$result = $conn->query($sql);
ob_start();
while($row = $result->fetch_assoc() {
$output .= "<tr>";
$output .= "<td>" . $row['name'] . "</td>";
$basic_pay=basic_pay($row["employee_id"],$date);
$output .= "<td>" . $basic_pay . "</td>";
$rate_per_day=rate_per_day($row["employee_id"],$date);
$output .= "<td>" . $rate_per_day . "</td>";
$rate_per_hour=rate_per_hour($row["employee_id"],$date);
$output .= "<td>" . $rate_per_hour . "</td>";
$overtime=overtime($row["employee_id"],$date);
$output .= "<td>" . $overtime . "</td>";
$allowance=allowance($row["employee_id"],$date);
$output .= "<td>" . $allowance . "</td>";
$commissions=commissions($row["employee_id"],$date);
$output .= "<td>" . $commissions . "</td>";
$housing_fee=housing_fee($row["employee_id"],$date);
$output .= "<td>" . $housing_fee . "</td>";
$cash_advances=cash_advances($row["employee_id"],$date);
$output .= "<td>" . $cash_advances . "</td>";
$loans=loans($row["employee_id"],$date);
$output .= "<td>" . $loans . "</td>";
$coop_share=coop_share($row["employee_id"],$date);
$output .= "<td>" . $coop_share . "</td>";
$sss=sss($row["employee_id"],$date);
$output .= "<td>" . $sss . "</td>";
$philhealth=philhealth($row["employee_id"],$date);
$output .= "<td>" . $philhealth . "</td>";
$pagibig=pagibig($row["employee_id"],$date);
$output .= "<td>" . $pagibig . "</td>";
$personal_gas=personal_gas($row["employee_id"],$date);
$output .= "<td>" . $personal_gas . "</td>";
$absences=absences($row["employee_id"],$date);
$output .= "<td>" . $absences . "</td>";
$withholding_tax=withholding_tax($row["employee_id"],$date);
$output .= "<td>" . $withholding_tax . "</td>";
$salary_differential = salary_differential($row["employee_id"],$date);
$output .= "<td>" . $salary_differential . "</td>";
$total = $basic_pay + $overtime + $allowance + $commissions - $housing_fee - $coop_share - $sss - $philhealth - $pagibig - $cash_advances -$loans - $personal_gas - $absences - $withholding_tax + $salary_differential;
$output .= "<td>" . $total . "</td>";
$output .= "</tr>";
}
$output .= "</tr>";
$output .= "</table>";
return $output;
$conn->close();
}
// Include the main TCPDF library (search for installation path).
require_once(dirname(dirname(__FILE__)) . '/tcpdf/tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetAuthor('CCJD Camarao Ventures, Inc.');
$pdf->SetTitle('Payroll Report: ' . $date->format('m-d-Y'));
// set default header data
$pdf->SetHeaderData('logo.jpg', PDF_HEADER_LOGO_WIDTH, $companyname, '', $address);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// add a page
$pdf->AddPage('L', 'LETTER');
$html=fetchdata($date);
$html = ob_get_contents();
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
echo $pdf->lastPage();
ob_end_clean();
//Close and output PDF document
echo $pdf->Output('PayrollReport $date', 'I');
?>