表示したい日付範囲を表示する 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();
?>