Hi,
im creating some PDF Files out of SQL Selects using the PHP-PDF class from this site:
The Code is working in generally,
but then i had the idea to reformat the prices in the table.
a) OLD WAY was completly ok, except the price-format
b) NEW WAY has the problem that the table header is not displayed with labels.
The table header is just named like Array numbers.
So my table header is named: 0 ,1, 2,3,4,5,6
The consequence is, that the following part in my source ( keyword: tableoptions) are partly ignored.
I hope you can see & understand my problem, otherwise i will try to explain it in more detail.
I know that the problem must be in relationship with the array, but i really dont find the bug. Perhabs im getting blind
<?php
// DB cfg
include 'inc/config.php';
//
error_reporting(E_ALL);
// PDF PHP classe
include './pdf_php_0_09/class.ezpdf.php';
//
$pdf =& new Cezpdf('a4');
// Font
$pdf->selectFont('./pdf_php_0_09/fonts/Helvetica');
// Connect DB
@mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) OR die(mysql_error());
mysql_select_db(MYSQL_DATABASE) OR die(mysql_error());
//
// errechne das Vorjahr
$query = "SELECT EXTRACT(YEAR FROM CURDATE())-1";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$query = " SELECT KIS_kostenstelle.kostenstelle_id AS 'KST-Nr.',
KIS_kostenstelle.kostenstelle_bezeichnung AS 'KST-Name',
KIS_artikel.artikel_datev_nummer AS 'Datev-Nr.',
KIS_artikel.artikel_inv_nummer AS 'Inv-Nr.',
KIS_artikel.artikel_bezeichnung AS 'Bezeichnung',
date_format(KIS_artikel.artikel_kaufdatum, '%d.%m.%Y') AS 'Rech.-datum',
REPLACE(KIS_artikel.artikel_einkaufspreis,'.',',') AS 'EK-Preis'
FROM KIS_artikel,
KIS_kostenstelle
WHERE artikel_kaufdatum LIKE '".$row[0]."%' AND
KIS_kostenstelle_kostenstelle_id = kostenstelle_id
ORDER BY KIS_kostenstelle_kostenstelle_id ASC,
artikel_kaufdatum ASC
";
//
//init des arrays
$data = array();
// Do Query
$result = mysql_query($query);
//ist der result identifier korrekt ?
if (!$result)
{
echo mysql_error();
exit;
}
//
// NEW -STYLE- WRECKED
while($tmp = mysql_fetch_assoc($result))
{
$data[] = array($tmp['KST-Nr.'] ,$tmp['KST-Name'],$tmp['Datev-Nr.'],$tmp['Inv-Nr.'],$tmp['Bezeichnung'],$tmp['Rech.-datum'],number_format($tmp['EK-Preis'],2,',','.'));
}
// OLD WORKING STYLE !!!!!!!!!!!!!!
// problem here: float-value is bad formated
//while($data[] = mysql_fetch_array($result, MYSQL_ASSOC)) {}
$tableoptions = array
(
'width' => 500,
'shaded' => 2,
'showHeadings' => 1, // zeig Überschriften der spalten
'showLines'=>2, // Mach Linien
'lineCol' => array(0.0,0.0,0.0), // Linienfarbe, hier schwarz
'xPos'=> 50,
'xOrientation'=>'right',
'fontSize' => 10, // schriftgroesse
'titleFontSize' => 12, // schriftgroesse überschrift
'splitRows' => 0,
'protectRows'=>2,
'innerLineThickness' => 0.5,
'outerLineThickness' => 0.5,
'rowGap' => 1,
'colGap' => 5,
'cols' => array
(
'KST-Nr.' =>array('justification'=>'left','width'=>50),
'KST-Name' =>array('justification'=>'left','width'=>100),
'Datev-Nr' =>array('justification'=>'left','width'=>50),
'Inv-Nr.' =>array('justification'=>'left','width'=>50),
'Bezeichnung' =>array('justification'=>'left','width'=>100),
'Rech.-datum' =>array('justification'=>'right','width'=>100),
'EK-Preis' =>array('justification'=>'right','width'=>50),
),
) ;
//
//
$pdf->ezTable($data,'','',$tableoptions );
// make table
// $pdf->ezTable($data);
//
// do output
if (isset($d) && $d)
{
$pdfcode = $pdf->output(1);
$pdfcode = str_replace("n","n<br>", htmlspecialchars($pdfcode));
echo '<html><body>';
echo trim($pdfcode);
echo '</body></html>';
}
else
{
$pdf->stream();
}
?>
i have tested with var_dump, but i really cant find the mistake.
In both cases it looks for me, like the array has the same content & the only diffrence in the output is/are the table headers.
ciao & best regards
fidel_