如何使用php将数据从mysql打印成pdf文件

时间:2014-02-10 08:06:36

标签: php mysql pdf

我使用fdf.php扩展名将数据打印成pdf文件...我的代码没有给出任何错误或警告,只是它确实从数据库中检索任何内容 请帮忙: 我的代码是: 我有一个名为candidate

的数据库表
<?php


include "connection.php";

require('fpdf.php');

class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('home.jpg',10,6,30);
// Arial bold 15
$this->SetFont('Arial','B',12);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(60,10,'hello world',0,0,'C');
// Line break
$this->Ln(8);

$this->Cell(200,10,'Leh, Ladakh',0,0,'C');


$this->Ln(20);

}

// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-15);
// Arial italic 8
$this->SetFont('Arial','I',8);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}



// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);

$result="select * from candidates";

$rows = mysql_query($result); 


while($row=mysql_fetch_array($rows, MYSQL_ASSOC))
{



$pdf->Cell(0,10,'Member id:', "{$row['mem_id']}"); 
$pdf->Ln();
$pdf->Cell(0,10,'course name:', "{$row['course_name']}");
$pdf->Ln();
$pdf->Cell(0,10,'course nature:', "{$row['course_nature']}");
$pdf->Ln();
$pdf->Cell(0,10,'duration:' ,"{$row['duration']}");
$pdf->Ln();
$pdf->Cell(0,10,'name:' ,"{$row['name']}");
$pdf->Ln();
$pdf->Cell(0,10,'parentage:', "{$row['parentage']}");
$pdf->Ln();
$pdf->Cell(0,10,'date of birth:', "{$row['d_o_b']}");
$pdf->Ln();
$pdf->Cell(0,10,'gender:', "{$row['gender']}");
$pdf->Ln();
$pdf->Cell(0,10,'qualification:', "{$row['qualification']}");
$pdf->Ln();
$pdf->Cell(0,10,'address:', "{$row['address']}");
$pdf->Ln();
$pdf->Cell(0,10,'contact number:', "{$row['contact_number']}");
$pdf->Ln();
$pdf->Cell(0,10,'catagory:' ,"{$row['catagory']}");

}
$pdf->Output();

?>

0 个答案:

没有答案