首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >单元格中的FPDF If语句

单元格中的FPDF If语句
EN

Stack Overflow用户
提问于 2014-04-26 11:18:21
回答 1查看 3.1K关注 0票数 0

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

这个文件可以工作,但我在标题部分有一个问题,这是代码:

代码语言:javascript
复制
//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月是01Feb= 02,依此类推,直到12月= 12。

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

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

EN

回答 1

Stack Overflow用户

发布于 2014-04-27 10:29:47

不要混合使用$this(类成员)和$pdf(类对象)

代码语言:javascript
复制
//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
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23306222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档