У меня есть FPDF для создания списка членов из базы данных Mysql в список в формате PDF. Но после того, как мой сайт-хост обновил версию php, список моих участников не работает!FPDF не работает сейчас - сработал?
Теперь шоу:
Warning: Invalid argument supplied for foreach() in /customers/8/f/b/xxx.com/httpd.www/test/printmedlemsliste.php on line 46 FPDF error: Some data has already been output, can't send PDF file (output started at /customers/8/f/b/xxx.com/httpd.www/test/printmedlemsliste.php:46)
Мой код:
<?php
require('fpdf.php');
class People {
public function all() {
try {
$db = new PDO('mysql:host=localhost;dbname=xxx_com;charset=UTF-8', 'xxx_com', 'xxx');
$query = $db->prepare("SELECT o.user_post, o.user_name1, o.user_name2, o.user_address1, o.user_address2, o.user_phone1, o.user_phone2, c.user_email, o.user_type FROM e107_user c, e107_user_extended o WHERE c.user_id = o.user_extended_id Order By user_name1");
$query->execute();
$people = $query->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
//echo "Exeption: " .$e->getMessage();
$result = false;
}
$query = null;
$db = null;
return $people;
}
}
class PeoplePDF extends FPDF{
// Create basic table
public function BasicTable($header, $data)
{
// Header
$this->SetFont('','B', 12);
$this->Cell(0,6,'Medlemsliste'.'',1,1,'C');
$this->SetFont('','B', 9);
$dateinvoice = substr($invoice[ 'dateinvoice' ], 6).substr($invoice[ 'dateinvoice' ], 3, 2).substr($invoice[ 'dateinvoice' ], 0, 2);
$dateinvoice = date_create($dateinvoice);
$dateinvoice = false === $dateinvoice ? '' : $dateinvoice->format('d-M-Y');
$this->Cell(10); $this->Cell(17, 5, 'Print Dato:'); $this->Cell(17, 5, $dateinvoice, 0, 1);
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('','B');
foreach ($header as $col) {
//Cell(float w [, float h [, string txt [, mixed border [, int ln [, string align [, boolean fill [, mixed link]]]]]]])
$this->Cell($col[1], 5, $col[0], 1, 0, 'L', true); }
$this->Ln();
// Data
$this->SetFillColor(255);
$this->SetTextColor(0);
$this->SetFont('');
foreach ($data as $row)
{
$i = 0;
foreach ($row as $field) {
$this->Cell($header[$i][1], 6, $field, 1, 0, 'L', true);
$i++;
}
$this->Ln();
}
}
}
// Column headings
$header = array(
array('Post', 20),
array('Fornavn', 18),
array('Efternavn', 46),
array('Adresse', 40),
array('Postnummer & By', 40),
array('Telefon', 22),
array('Mobil', 22),
array('E-Mail', 57),
array('Type', 12)
);
// Get data
$people = new People();
$data = $people->all();
$pdf = new PeoplePDF();
$pdf->SetFont('Arial', '', 9);
$pdf->AddPage('L');
$pdf->Ln(0);
$pdf->SetTitle("Medlemsliste", boolean);
$pdf->SetAuthor("-");
$pdf->BasicTable($header,$data);
$pdf->Output('yourfilename.pdf','D');
?>
Линия 46 является foreach ($data as $row)
.
Если установить //
фронт foreach ($data as $row)
, это новая ошибка на линии 49. Линия 49 является foreach ($row as $field) {
Кроме того, если я изложу //
перед линией 49, она генерирует файл PDF, но без каких-либо данных в!
Может ли кто-нибудь помочь?