【问题标题】:FPDF If statements in a cell单元格中的 FPDF If 语句
【发布时间】:2014-04-26 03:18:21
【问题描述】:

您将在下面看到一个代码,用于在月末生成报告,这是一个单击以生成报告的按钮,它按月份和年份排序。

这个文件有效,但我在标题部分有问题,这是代码:

//Title
$this->SetFont('Arial','',18);
$this->Image('media/logo.png');
$this->Ln(10);
$this->Cell(0,6,'Generated Reports',0,1,'C');
$this->Cell(0,7,'As of Month of ',0,2,'C');
if($date=="01")
{
$pdf->Cell(0,8,'January',0,3,'C');
}
else if($date=="02")
{
$pdf->Cell(0,8,'February',0,3,'C');
}
else if($date=="03")
{
$pdf->Cell(0,8,'March',0,3,'C');
}
else if($date=="04")
{
$pdf->Cell(0,8,'April',0,3,'C');
}
else if($date=="05")
{
$pdf->Cell(0,8,'May',0,3,'C');
}
else if($date=="06")
{
$this->Cell(0,8,'June',0,3,'C');
}
else if($date=="07")
{
$this->Cell(0,8,'July',0,3,'C');
}
else if($date=="08")
{
$this->Cell(0,8,'August',0,3,'C');
}
else if($date=="09")
{
$this->Cell(0,8,'September',0,3,'C');
}
else if($date=="10")
{
$this->Cell(0,8,'October',0,3,'C');
}
else if($date=="11")
{
$this->Cell(0,8,'November',0,3,'C');
}
else if($date=="12")
{
$this->Cell(0,8,'December',0,3,'C');
}
$this->Ln(10);
//Ensure table header is output
parent::Header();

日期以数字表示,因此 1 月为 2 月 01 日 = 02,依此类推,直到 12 月 = 12。

正如您在上面看到的,我尝试使用 if,甚至将 $this 更改为 $pdf,但仍然无济于事。

它将生成一个 PDF 文件,但没有月份,它只会生成“截至月份”及其下方的详细信息,而不是生成它的月份。

【问题讨论】:

    标签: php pdf fpdf


    【解决方案1】:

    我会建议你使用数组来管理它。

    不要混用 $this(Class member) 和 $pdf(Class Object)

    //Title    
    $this->SetFont('Arial','',18);
    $this->Image('media/logo.png');
    $this->Ln(10);
    $this->Cell(0,6,'Generated Reports',0,1,'C');
    
    $monthArray = array("January","February","March","April","May","June","July","August","September","October","November","December");
    
    $index = intval($date)-1;
    
    $this->Cell(0,7,'As of Month of '.$monthArray[$index],0,2,'C');
    $this->Ln(10);
    //Ensure table header is output
    parent::Header();
    

    【讨论】:

    • 感谢您的帮助,但问题仍然存在。它仍然不会输出月份。我可以把整个代码发给你,但它是 23mb 的文件。
    • 尝试和测试$this->Cell(0,7,'As of Month of '.$date,0,2,'C');
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 2018-02-11
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    相关资源
    最近更新 更多