Hallo, ik wil met FPDF de inhoud van de tabel "klanten" wegschrijven in een pdf-formaat. In de tabel zitten 5 records maar met onderstaande code wordt slechts alleen de laatste record afgedrukt ... De code is een ( door mij aangepaste ) voorbeeldcode die je kan vinden op www.fpdf.org . Waarom word alleen de laatste record verstuurd naar het pdf bestand ?
Dank ..
<?php
require('fpdf.php');
//Connect to your database
$hostname = "localhost";
$username= "root";
$password= "my_password";
$dbid="my_database";
$link=mysql_connect($hostname, $username, $password);
mysql_select_db($dbid) or die ("Unable to connect to MySQL");
//Select the Products you want to show in your PDF file
$result=mysql_query("select knID,voornaam,achternaam from klanten Order by knID",$link);
$number_of_products = mysql_numrows($result);
//For each row, add the field to the corresponding column
while($row = mysql_fetch_array($result))
{
$knID = $row["knID"];
$voornaam = $row["voornaam"];
$achternaam = $row["achternaam"];
}
mysql_close();
//Create a new PDF file
$pdf=new FPDF();
$pdf->AddPage();
//Fields Name position
$Y_Fields_Name_position = 20;
//Table position, under Fields Name
$Y_Table_Position = 26;
//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(45);
$pdf->Cell(20,6,'knID',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(100,6,'voornaam',1,0,'L',1);
$pdf->SetX(135);
$pdf->Cell(30,6,'achternaam',1,0,'R',1);
$pdf->Ln();
//Now show the 3 columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(45);
$pdf->MultiCell(20,6,$knID,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(100,6,$voornaam,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$achternaam,1,'R');
//Create lines (boxes) for each ROW (Product)
//If you don't use the following code, you don't create the lines separating each row
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products)
{
$pdf->SetX(45);
$pdf->MultiCell(120,6,'',1);
$i = $i +1;
}
$pdf->Output();
?>
901 views