【发布时间】:2016-01-14 19:17:50
【问题描述】:
我已经尝试过有关 fpdf 的教程,并到处搜索有用的代码。我发现了我认为可以在 SO 上解决问题的方法。也就是说,按照here 的例子并没有产生好的结果。我肯定需要这方面的帮助。
这是我的代码:
<?php
require_once '../root_login.php';
require('fpdf.php');
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
//$this->Image('images/bg_all.jpg',10,6,30);
// Arial bold 15
$this->SetFont('Times','B',20);
// Move to the right
$this->Cell(80);
// Title
$this->Cell(40,10,'B A S E B A L L',0,0,'C');
// Line break
$this->Ln(6);
// Arial bold 15
$this->SetFont('Arial','B',9);
$this->Cell(200,10,'LITTLE LEAGUE ROSTERS',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','',8);
$stmt = $db->prepare('SELECT fname, lname
FROM rosters
ORDER BY lname');
$stmt->execute();
$result = $stmt->fetchALL(PDO::FETCH_ASSOC);
foreach($result as $row) {
$pdf->Cell(0,10,'F NAME:', $row['fname']);
$pdf->Ln();
$pdf->Cell(0,5,'L NAME:', $row['lname']);
$pdf->Ln();
}
$pdf->Output();
?>
可以查看输出here
有人看到我做错了吗?为什么要画这些线?谢谢。
【问题讨论】:
-
你没有连接到数据库。
-
@JayBlanchard - 那为什么我会通过 $results 打印出 F NAME & L NAME?对于我在 db 表中的相同数量的人?最初我认为你说的很对,所以我将 root_login.php 移到了工作文件夹。这使差异为零。
-
root_login 是否包含与数据库的连接?
-
@JayBlanchard - 是的。这与我在我的网站上用于连接的凭据相同。这就是为什么我不知所措,因为我知道那是正确的。它只是不会输出数据。如果它没有遍历 $results,那将很容易查明。但它正在运行 db 表并打印出正确数量的 F NAME 和 LNAME。只是不是孩子们的名字。更不用说它画的疯狂线条了。另一个谜,那个。
-
您确定列名吗?没有字母大小写问题?这些行来自
cell的默认值。根据我的经验,您应该始终完全定义 FPDF 中的所有单元格选项。