2013-05-18 130 views
1
<?php 

$factuurnr = $_GET['factuurnr']; 



require('fpdf/fpdf.php'); 

//Connect to your database 
include("db_connect.php"); 

//Create new pdf file 
$pdf=new FPDF(); 

//Open file 
$pdf->Open(); 

//Disable automatic page break 
$pdf->SetAutoPageBreak(false); 

//Add first page 
$pdf->AddPage(); 

//set initial y axis position per page 
$y_axis_initial = 25; 

//print column titles for the actual page 
$pdf->SetFillColor(232, 232, 232); 
$pdf->SetFont('Arial', 'B', 12); 
$pdf->SetY($y_axis_initial); 
$pdf->SetX(25); 
$pdf->Cell(30, 6, 'klantnummer', 1, 0, 'L', 1); 
$pdf->Cell(100, 6, 'factuurnummer', 1, 0, 'L', 1); 
$pdf->Cell(30, 6, 'bedrag', 1, 0, 'R', 1); 

$y_axis = $y_axis + $row_height; 

//Select the Products you want to show in your PDF file 
$query="SELECT * FROM facturen WHERE factuurnummer = '$factuurnr'"; 
$result=mysql_query($query); 



//initialize counter 
$i = 0; 

//Set maximum rows per page 
$max = 25; 

//Set Row Height 
$row_height = 6; 

while($row = mysql_fetch_array($result)) 
{ 
//If the current row is the last one, create new page and print column title 
if ($i == $max) 
{ 
    $pdf->AddPage(); 

    //print column titles for the current page 
    $pdf->SetY($y_axis_initial); 
    $pdf->SetX(25); 
    $pdf->Cell(30, 6, 'klantnummer', 1, 0, 'L', 1); 
    $pdf->Cell(100, 6, 'factuurnummer', 1, 0, 'L', 1); 
    $pdf->Cell(30, 6, 'bedrag', 1, 0, 'R', 1); 

    //Go to next row 
    $y_axis = $y_axis + $row_height; 

    //Set $i variable to 0 (first row) 
    $i = 0; 
} 

$klantnummer = $row['klantnummer']; 
$factuurnummer = $row['factuurnummer']; 
$bedrag = $row['bedrag']; 

$pdf->SetY($y_axis); 
$pdf->SetX(25); 

$pdf->Cell(30, 6, $klantnummer, 1, 0, 'L', 1); 
$pdf->Cell(100, 6, $factuurnummer, 1, 0, 'L', 1); 
$pdf->Cell(30, 6, $bedrag, 1, 0, 'R', 1); 

//Go to next row 
$y_axis = $y_axis + $row_height; 
$i = $i + 1; 
} 

mysql_close; 

//Create file 
$pdf->Output(); 
?> 

我正在嘗試使用fpdf生成帶有來自MySQL的信息的pdf。說實話,它正在工作,但是渲染關閉了,我太新來fpdf瞭解這一點。如何提高FPDF渲染?

來自MySQL的數據在表頭以上呈現,我不知道爲什麼。

+0

[**請不要在新代碼中使用'mysql_ *'函數**](http://bit.ly/phpmsql)。他們不再被維護[並被正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://www.brightmeup.info/article.php?a_id=2)。 –

+1

thnx指向我不贊成的信息,和教程 – defiancenl

回答

1

也許你的初始設置$ y_axis是錯誤的。 試試這個:

$y_axis = $y_axis_initial + $row_height; 

我想你應該更換你的3 '$ Y_AXIS = ...' 線(最後一個是OK)2。

+0

thnx男人,這確實是問題。 – defiancenl