<?php
define('FPDF_FONTPATH', '/fpdf/font/');
require('/fpdf/fpdf.php');
//Connect to your database
include("conectmysql.php");
class PDF extends FPDF
{
// Page header
function Header()
{
// Logo
$this->Image('logo.jpg',95,10,42);
// Arial bold 15
// Line break
$this->Ln(20);
}
// Page footer
function Footer()
{
// Position at 1.5 cm from bottom
$this->SetY(-20);
// Arial italic 8
$this->SetFont('Arial','I',9);
// Page number
$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
$this->Cell(0,10,'Powered By: Tahmid Soft',0,0,'R');
}
}
// Instanciation of inherited class
$pdf = new PDF('P','mm',array(225,340));
$pdf->AliasNbPages();
$pdf -> AddPage();
$pdf->SetFont('Times','',12);
//set initial y axis position per page
$row_height = 5;
$y_axis_initial = 25;
$y_axis_initial1 = 0;
//print column titles for the actual page
$pdf->SetFillColor(232, 232, 232);
$pdf->SetFont('Arial', 'B', 12);
$pdf->SetY(32);
$pdf->SetX(25);
$pdf->Cell(30, 6, 'QTY', 1, 0, 'L', 1);
$pdf->Cell(100, 6, 'PRICE', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'AMOUNT', 1, 0, 'R', 1);
$y_axis=33;
$y_axis = $y_axis + $row_height;
//Select the Products you want to show in your PDF file
$result=mysql_query('select QTY, PRICE, AMOUNT from pi where PI_NO="3"', $link);
//initialize counter
$QTY = "";
$PRICE = "";
$AMOUNT = "";
$total = 0;
$i = 0;
//Set maximum rows per page
$max = 30;
//Set Row Height
$row_height = 5;
while($row = mysql_fetch_array($result) )
{
//If the current row is the last one, create new page and print column title
if ($i == $max)
{
$pdf->AddPage();
//print column titles for the current page
$pdf->SetY(32);
$pdf->SetX(25);
$pdf->Cell(30, 6, 'QTY', 1, 0, 'L', 1);
$pdf->Cell(100, 6, 'PRICE', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'AMOUNT', 1, 0, 'R', 1);
$y_axis=33;
//Go to next row
$y_axis = $y_axis + $row_height;
//Set $i variable to 0 (QTY row)
$i = 0;
}
$QTY = $row['QTY'];
$PRICE = $row['PRICE'];
$AMOUNT = $row['AMOUNT'];
$total = $total+$AMOUNT;
$pdf->SetY($y_axis);
$pdf->SetX(25);
$pdf->Cell(30, 6, $QTY, 1, 0, 'L', 1);
$pdf->Cell(100, 6, $PRICE, 1, 0, 'L', 1);
$pdf->Cell(30, 6, $AMOUNT, 1, 0, 'R', 1);
//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
$pdf->SetY($y_axis + 1);
$pdf->SetX(105);
$pdf->Cell(50, 6, ' SUB TOTAL ',1,0, 'R',1);
$pdf->SetX(155);
$pdf->Cell(30, 6, '$ '.$total, 1, 0, 'R', 1);
}
mysql_close($link);
//Create file
$pdf->Output();
?>
&#13;
我试图根据从mysql表中检索的列值来获取每个页面上的列值的总和。我正在使用fpdf获取pdf输出。目前它在每个页面上总共提供一列(AMOUNT)。但是在第2页的第一页之后,它正在添加以前的页面值。
如果有人可以帮助我,那么我可以完成我的项目。感谢
里彭
答案 0 :(得分:0)
答案 1 :(得分:0)
在最后的if ($i == $max)
块中添加$total = 0;
这会将每个页面的总数设置为0,然后开始向其添加金额,并显示正确的价格。
if ($i == $max)
{
$pdf->AddPage();
//print column titles for the current page
$pdf->SetY(32);
$pdf->SetX(25);
$pdf->Cell(30, 6, 'QTY', 1, 0, 'L', 1);
$pdf->Cell(100, 6, 'PRICE', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'AMOUNT', 1, 0, 'R', 1);
$y_axis=33;
//Go to next row
$y_axis = $y_axis + $row_height;
//Set total to 0 at each new page otherwise it will carry the price offer from the last page
$total = 0;
//Set $i variable to 0 (QTY row)
$i = 0;
}