我在 FPDF 显示我想要显示的日期范围时遇到问题。它每次都会从数据库的开头提取每个日期。不管我把它放在什么范围内,它都是从开始到结束的日期。任何帮助都会有所帮助。
这是代码:
<?php
define('FPDF_FONTPATH','font/');
require('mysql_table.php');
class PDF extends PDF_MySQL_Table
{
function Header()
{
//Title
$this->Image('eagle.png',10,6,30);
$this->Image('eagle.png',170,6,30);
$this->SetFont('Arial','',18);
$this->Cell(0,6,'Range Report',0,1,'C');
$this->Ln(20);
//Ensure table header is output
parent::Header();
}
}
//Connect to database
mysql_connect('localhost','root','');
mysql_select_db('charitabledb');
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
//table: specify 4 columns
$pdf->AddCol('date',20,'Date','C');
$pdf->AddCol('transactiontype',30,'Transaction','L');
$pdf->AddCol('account',40,'Account','L');
$pdf->AddCol('description',60,'Description','L');
$pdf->AddCol('Expense',20,'Expense','R');
$pdf->AddCol('Income',20,'Income','R');
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>2);
$startdate=$_Post['startdate'];
$enddate=$_POST['enddate'];
$pdf->Table("SELECT * FROM accounting WHERE date between '" . $startdate . "' AND '" .
$enddate . "' order by date ASC",$prop);
$pdf->AddCol('',150,'');
$pdf->AddCol('Sum(Expense)',40,'Total Expense','R');
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>2);
$pdf->Table("select Sum(Expense) from accounting WHERE date between '" . $startdate . "'
AND '" . $enddate . "'",$prop);
$pdf->AddCol('',150,'');
$pdf->AddCol('Sum(Income)',40,'Total Income','R');
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>2);
$pdf->Table("select Sum(Income) from accounting WHERE date between '" . $startdate . "'
AND '" . $enddate . "'",$prop);
$pdf->AddCol('',150,'');
$pdf->AddCol('Sum(Income)-Sum(Expense)',40,'Total Revenue','R');
$prop=array('HeaderColor'=>array(255,150,100),
'color1'=>array(210,245,255),
'color2'=>array(255,255,210),
'padding'=>2);
$pdf->Table("select Sum(Income)-Sum(Expense) from accounting WHERE date between '" .
$startdate . "' AND '" . $enddate . "'",$prop);
$pdf->Output();
?>