2014-04-26 38 views
0

您将在下面看到的是用于在月末生成报表的代码,该按钮是一个单击以生成报表的按钮,并且按月份和年份排序。FPDF如果单元格中的语句

此文件的工作,但我在报头部分的一个问题是这样的代码:

//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(); 

日期是在数量因此一月份为02月01日= 02,以此类推,直到十二月= 12

正如你可以看到上面我尝试使用,如果甚至改变$this$pdf但仍然无济于事。

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

回答

0

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

不要混用和思念使用$这个(类成员)& $ PDF(类对象)

//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(); 
+0

感谢您的帮助,但问题依然存在。它仍然不会输出这个月份。我可以寄给你全部的代码,但它是23MB文件。 –

+0

你测试的$日期有一个正确的变量? –

+0

尝试并测试'$ this-> Cell(0,7,'Month of'。$ date,0,2,'C');' –