我試圖創建fpdf17
一個PDF表格,並正在就這一if
說法(不是}
)的最後一行得到一個錯誤致命錯誤
if($fill || $border==1)
{
if($fill)
$op = ($border==1) ? 'B' : 'f';
else
$op = 'S';
$s = sprintf('%.2F %.2F %.2F %.2F re %s ',$this->x*$k,($this->h-$this->y)*$k,$w*$k,-$h*$k,$op);
}
錯誤說:Fatal error: Unsupported operand types in C:\myfilepath\fpdf17\fpdf.php on line 630
我有兩類參與:我PDFTable類:
<?php
require('../fpdf17/fpdf.php');
class PDFTable extends FPDF
{
// Load data
function LoadData($file)
{
// Read file lines
$lines = file($file);
$data = array();
foreach($lines as $line)
$data[] = explode(';',trim($line));
return $data;
}
// Simple table
function BasicTable($header, $data)
{
// Header
foreach($header as $col)
$this->Cell(40,7,$col,1);
$this->Ln();
// Data
foreach($data as $row)
{
foreach($row as $col)
$this->Cell(40,6,$col,1);
$this->Ln();
}
}
// Better table
function ImprovedTable($header, $data, $widths)
{
// Column widths
$w = $widths;
// Header
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C');
$this->Ln();
// Data
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR');
$this->Cell($w[1],6,$row[1],'LR');
$this->Cell($w[2],6,$row[1],'LR');
$this->Cell($w[3],6,$row[1],'LR');
$this->Cell($w[4],6,$row[1],'LR');
$this->Ln();
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
// Colored table
function FancyTable($header, $data)
{
// Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
// Header
$w = array(40, 35, 40, 45);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
$this->Ln();
// Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,number_format($row[2]),'LR',0,'R',$fill);
$this->Cell($w[3],6,number_format($row[3]),'LR',0,'R',$fill);
$this->Ln();
$fill = !$fill;
}
// Closing line
$this->Cell(array_sum($w),0,'','T');
}
}
?>
和我Deposits
類甚至不被稱爲所以沒關係。
這裏是我創造的一切:
<?php
//check if logged in
require_once('../config/db.php');
require_once('../classes/Login.php');
$login = new Login();
if ($login->isUserLoggedIn() == false) { $login->doLogout(); }
//Connect to your database
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);
require_once('deposit_class.php');
require_once('table_class.php');
$deposit = new Deposit();
$pdf = new PDFTable();
$query = "SELECT r.departure AS depart, r.id AS reservation, u.unit_name AS unit,
CONCAT(g.fname, ' ', g.lname) AS guest, SUM(p.payment_amt) AS total
FROM reservations r
JOIN units u ON r.unit = u.id
JOIN guests g ON r.guest = g.id
JOIN payments p ON r.id = p.reservation
WHERE r.departure >= LAST_DAY(NOW() - INTERVAL 1 MONTH) + INTERVAL 1 DAY
GROUP BY r.id
ORDER BY r.departure ASC";
$result = mysqli_query($con, $query);
$file = 'deposits.txt';
while ($row = mysqli_fetch_assoc($result)) {
$content = $row['depart'].';'.$row['reservation'].';'.$row['unit'].';'.$row['guest'].';'.$row['total'].'\n';
file_put_contents($file, $content, FILE_APPEND | LOCK_EX);
}
$pdf->SetFont('Arial','',14);
$pdf->AddPage();
//send file to Table
$data = $pdf->LoadData($file);
unlink('deposits.txt'); //unlink file
//create header
$header[] = array("Depart", "Reservation", "Unit", "Guest", "Total");
//create table
$widths[] = array(25,20,40,40,15);
$deposit_table = $pdf->ImprovedTable($header, $data, $widths);
$pdf->Output();
?>
任何想法,爲什麼我收到錯誤?它似乎在這裏發生:$deposit_table = $pdf->ImprovedTable($header, $data, $widths);
我在其他地方使用它就好了。
編輯:
// Header
for($i=0;$i<count($header);$i++){
echo "here";
$this->Cell($w[$i],7,$header[$i],1,0,'C');
}
$this->Ln();
*究竟是什麼*錯誤? – LSerni
我將它添加到帖子中。 –
@Iserni檢查我的編輯 –