我在fpdf中执行SQL查询时遇到了一些问题,这可能吗?
我目前有
session_start();
require('fpdf.php');
class PDF extends FPDF
{
function Header()
{
include('config.php');
$client_check = $db->prepare("SELECT * FROM clients WHERE client_fullname = '".$_SESSION['client_details']."'");
$client_check->execute();
while ($row = $client_check->fetch(PDO::FETCH_ASSOC))
{
$client_firstname = $row ['client_firstname'];
$client_lastname = $row ['client_lastname'];
$client_address = $row ['client_address'];
$client_jobaddress = $row ['client_jobaddress'];
$client_homephone = $row ['client_homephone'];
$this->SetFont('Arial', 'B', 12);
$this->Cell(10,0,'Ph(H):',0,0,'C');
$this->Cell(20,0,''.$client_homephone.'', 0,0,'C');
$this->Line(30,61,100,61);
$this->Cell(210,0,'Job No:',0,0,'C');
$this->Cell(-120,0,'Model:',0,0,'C');
$this->Line(110,61,200,61);
}
}
}
// Instanciation of inherited class
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',10);
$pdf->Output();在我添加while循环之前,一切都运行得很好。现在它只向我吐出一个空白的pdf。我该如何解决这个问题呢?
发布于 2013-03-14 10:22:24
$con = mysql_connect("localhost", "{username}", "{password}") or die(mysql_error()) ;
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db = mysql_select_db("{db}", $con) or die(mysql_error()) ;
$client= mysql_query("{SELECT * FROM clients}")or die(mysql_error());
while ($client2= mysql_fetch_array($client)){
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',10);
$pdf->Cell(20,0,''.$client2["client_homephone"].'', 0,0,'C');
.....
}
mysql_close($con);
$pdf->Output();发布于 2013-03-18 16:12:51
我恐怕你不能那样做,
这是因为每次向pdf添加新页面时都会运行头函数(如果页面溢出,则会自动执行此操作)。
相反,您可以这样做
创建一个PDF类的构造函数,该函数调用一个函数,比如将while循环调用到函数Fill_details
https://stackoverflow.com/questions/15353291
复制相似问题