In un DB di prova ho una tabella con i tre campi (sez, isc_mas, isc_fem) composta da 180 record.
Riescho a farmi stampare con fpdf le 180 righe contenenti i 3 campi e un quarto campo con la somma degli isc_mas+isc_fem)
questi sono i due file:
file prova1
Codice PHP:
<?php
define('FPDF_FONTPATH','font/');
include ("../../config.inc.php");
require('classe2.php');
class PDF extends PDF_classe1
{
function Header()
{
//Titolo
$this->SetFont('Arial','',18);
//sfondo titolo
$this->Ln();
$this->SetFillColor(255,200,0);
$this->SetX(85);
$this->Cell(50,6,'TITOLO',1,1,'C',1);
//spazio fra titolo e tabella
$this->Ln(15);
parent::Header();
}
}
$pdf=new PDF();
$pdf->Open();
$pdf->AddPage();
//Tabella iscritti
$pdf->Table('select sez, isc_mas, isc_fem from iscritti');
$pdf->Output();
?>
File classe1
Codice PHP:
<?php
require('../../fpdf153/fpdf.php');
class PDF_classe1 extends FPDF
{
function Header()
{
//Stampa la testata della tabella se necessario
if($this->ProcessingTable)
$this->TableHeader();
}
function TableHeader()
{
//Gray color filling each Field Name box
$this->SetFillColor(232,232,232);
$this->SetFont('Arial','B',12);
//$this->SetY($pos_verticale);
$this->SetX(65);
$this->Cell(20,6,'Sezione',1,0,'C',1);
$this->SetX(85);
$this->Cell(20,6,'Maschi',1,0,'C',1);
$this->SetX(105);
$this->Cell(20,6,'Femmine',1,0,'C',1);
$this->SetX(125);
$this->Cell(30,6,'Totale Sez',1,0,'C',1);
$this->Ln();
}
function Row($data)
{
$totaleriga = $data[isc_fem]+$data[isc_mas];
$totaleriga = number_format($totaleriga,',','.','.');
$this->SetFillColor(232,232,232);
$this->SetX(65);
$this->Cell(20,5,$data[sez],1,0,'R',1);
$this->SetX(85);
$this->Cell(20,5,$data[isc_mas],1,0,'R',1);
$this->SetX(105);
$this->Cell(20,5,$data[isc_fem],1,0,'R',1);
$this->SetX(125);
$this->Cell(30,5,$totaleriga,1,0,'R',1);
$this->Ln();
}
function Table($query)
{
//errore query
$res=mysql_query($query) or die('Error: '.mysql_error()."
Query: $query");
//Stampa le etichette nella prima pagina
$this->TableHeader();
$this->ProcessingTable=true;
while($row=mysql_fetch_array($res))
$this->Row($row);
}
}
?>
Il problema che non riesco a risolvere è quello di far stampare alla fine delle colonne il totale delle stesse.