| | | | |
| | ||
| Gast
Beiträge: n/a
| Hallo Leute, bin gerade etwas am verzweifeln, weil ich absolut nicht den Fehler finde. Ich habe eine MySQL-DB aus der Daten ausgelesen werden sollen und anschließend in einer PDF-Datei als Tabelle ausgegeben werden sollen. Hierzu nutze ich fpdf sowie die Klasse PDF_MySQL_Table: Code: <?php
require('fpdf.php');
class PDF_MySQL_Table extends fpdf
{
var $ProcessingTable=false;
var $aCols=array();
var $TableX;
var $HeaderColor;
var $RowColors;
var $ColorIndex;
function Header()
{
//Print the table header if necessary
if($this->ProcessingTable)
$this->TableHeader();
}
function TableHeader()
{
$this->SetFont('Arial', 'B', 12);
$this->SetX($this->TableX);
$fill=!empty($this->HeaderColor);
if($fill)
$this->SetFillColor($this->HeaderColor[0], $this->HeaderColor[1], $this->HeaderColor[2]);
foreach($this->aCols as $col)
$this->Cell($col['w'], 6, $col['c'], 1, 0, 'C', $fill);
$this->Ln();
}
function Row($data)
{
$this->SetX($this->TableX);
$ci=$this->ColorIndex;
$fill=!empty($this->RowColors[$ci]);
if($fill)
$this->SetFillColor($this->RowColors[$ci][0], $this->RowColors[$ci][1], $this->RowColors[$ci][2]);
foreach($this->aCols as $col)
$this->Cell($col['w'], 5, $data[$col['f']], 1, 0, $col['a'], $fill);
$this->Ln();
$this->ColorIndex=1-$ci;
}
function CalcWidths($width, $align)
{
//Compute the widths of the columns
$TableWidth=0;
foreach($this->aCols as $i=>$col)
{
$w=$col['w'];
if($w==-1)
$w=$width/count($this->aCols);
elseif(substr($w, -1)=='%')
$w=$w/100*$width;
$this->aCols[$i]['w']=$w;
$TableWidth+=$w;
}
//Compute the abscissa of the table
if($align=='C')
$this->TableX=max(($this->w-$TableWidth)/2, 0);
elseif($align=='R')
$this->TableX=max($this->w-$this->rMargin-$TableWidth, 0);
else
$this->TableX=$this->lMargin;
}
function AddCol($field=-1, $width=-1, $caption='', $align='L')
{
//Add a column to the table
if($field==-1)
$field=count($this->aCols);
$this->aCols[]=array('f'=>$field, 'c'=>$caption, 'w'=>$width, 'a'=>$align);
}
function Table($query, $prop=array())
{
//Issue query
$res=mysql_query($query) or die('Error: '.mysql_error()."
Query: $query");
//Add all columns if none was specified
if(count($this->aCols)==0)
{
$nb=mysql_num_fields($res);
for($i=0;$i<$nb;$i++)
$this->AddCol();
}
//Retrieve column names when not specified
foreach($this->aCols as $i=>$col)
{
if($col['c']=='')
{
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res, $col['f']));
}
}
//Handle properties
if(!isset($prop['width']))
$prop['width']=0;
if($prop['width']==0)
$prop['width']=$this->w-$this->lMargin-$this->rMargin;
if(!isset($prop['align']))
$prop['align']='C';
if(!isset($prop['padding']))
$prop['padding']=$this->cMargin;
$cMargin=$this->cMargin;
$this->cMargin=$prop['padding'];
if(!isset($prop['HeaderColor']))
$prop['HeaderColor']=array();
$this->HeaderColor=$prop['HeaderColor'];
if(!isset($prop['color1']))
$prop['color1']=array();
if(!isset($prop['color2']))
$prop['color2']=array();
$this->RowColors=array($prop['color1'], $prop['color2']);
//Compute column widths
$this->CalcWidths($prop['width'], $prop['align']);
//Print header
$this->TableHeader();
//Print rows
$this->SetFont('Arial', '', 11);
$this->ColorIndex=0;
$this->ProcessingTable=true;
while($row=mysql_fetch_array($res))
$this->Row($row);
$this->ProcessingTable=false;
$this->cMargin=$cMargin;
$this->aCols=array();
}
}
?>
Jedoch erhalte ich beim AUfruf der Datei "pdf_ausgabe.php" folgende Fehlermeldung: Zitat:
Code: <?php
define('FPDF_FONTPATH','font/');
include 'db_verbindung.php'; //Stellt die DB-Verbindung her
require('PDF_MySQL_Table.php');
require('fpdf.php'); //zur PDF-Erstellung
class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->SetFont('Arial', '', 18);
$this->Cell(0, 6, 'Tabellenausgabe als PDF', 0, 1, 'C');
$this->Ln(10);
//Ensure table header is output
parent::Header();
}
}
define('FPDF_FONTPATH','/font/');
//Erzeugung eins PDF-Dokumentes
$pdf=new FPDF();
$pdf -> Open();
$pdf->AddPage();
//First table: put all columns automatically
$pdf->Table('select * from kunden order by kdnr');
$pdf->Output();
?>
Gruß Oli ?>[/php] | |
| | |
| PHP Code Flüsterer Registriert seit: 21.08.2005 Beiträge: 4682 PHP-Kenntnisse: Fortgeschritten | |
| | ||
| Gast
Beiträge: n/a
| Zitat:
Gruß Oli | |
| | |
| Moderator Registriert seit: 03.09.2004
Beiträge: 11.792
PHP-Kenntnisse: Fortgeschritten ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | du musst dem browsers mittels header klarmachen dass jetzt pdf kommt.
__________________ robo47.net - Blog, Codeschnipsel und mehr | |
| |
| | |
| Moderator Registriert seit: 03.09.2004
Beiträge: 11.792
PHP-Kenntnisse: Fortgeschritten ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() | mit der funktion header() und der angabe des content-types für pdf (google vieleicht mal, weil alles weis ich auch ned ausm kopf :P) mfg robo47
__________________ robo47.net - Blog, Codeschnipsel und mehr | |
| |
| Themen-Optionen | |
| Thema bewerten | |
|
|
Ähnliche Themen | ||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| [Erledigt] MySQL Datenbank erstellen, nur wie? | Datenbanken | 9 | 24.04.2012 15:04 | |
| Datenbanktabelle erstellen - brauche Hilfe | Raccoon | PHP Tipps 2008 | 1 | 14.06.2008 11:03 |
| PHP <--> MySQL | Brauche Hilfe | ahnungsloser | Datenbanken | 18 | 16.02.2006 21:49 |
| Mysql startet nicht mehr ??? Hilfe ??? | c01001 | Datenbanken | 12 | 25.01.2006 00:10 |
| mysql dump erstellen | PHP Tipps 2005-2 | 4 | 03.09.2005 22:02 | |
| Suche Tipps für Persormance-Steigerung (Geld für Nützliches) | Beitragsarchiv | 18 | 16.08.2005 10:57 | |
| datenbanken in mysql erstellen??? | PHP Tipps 2005-2 | 0 | 05.08.2005 19:41 | |
| MySQL PrimaryKey von erstellen Datensatz? | PHP Tipps 2005 | 2 | 09.05.2005 02:31 | |
| mysql tabelle erstellen - name variable | möchtegernchegga | PHP Tipps 2005 | 10 | 24.04.2005 21:01 |
| Wieder mal MySQL Arlam !!! (datensatz erstellen) | PHP Tipps 2005 | 4 | 07.03.2005 21:08 | |
| [Erledigt] MySQL User erstellen | Datenbanken | 2 | 17.02.2005 17:23 | |
| brauche eure hilfe -> php mysql generell | Spyker | PHP Tipps 2005 | 3 | 30.01.2005 02:58 |
| mit mysql und php eine datenbank erstellen? Großes Problem | PHP Tipps 2004-2 | 1 | 16.12.2004 14:53 | |
| Wer kann mir in PHP MYSQL eine Datenbank erstellen? | Beitragsarchiv | 5 | 29.10.2004 12:05 | |
| neue mysql tabelle per php erstellen | PHP Tipps 2004 | 2 | 05.09.2004 16:02 | |
| Besucher kamen über folgende Suchanfragen bei Google auf diese Seite |
| fpdf table, fpdf mysql php, pdf aus mysql erstellen, http://www.php.de/php-tipps-2005/18494-pdf-aus-mysql-mit-hilfe-von-fpdf-erstellen.html, pdf_mysql_table, fpdf cmargin, fpdf tabelle mysql, php mysql pdf erstellen, fpdf mysql, fpdf tabelle erstellen, fpdf addcol, mysql pdf erstellen, fpdf tabelle ausgeben, fpdf umlaute, php mysql fpdf, pdf aus mysql, fpdf row, fpdf tabelle erstellen aus mysql datenbank, pdf aus mysql erzeugen, fpdf hilfe |

Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.