Codice PHP:
//qui mi connetto al db
$host = 'localhost';
$user = 'cswebuser';
$password = '';
$dbname = 'tuo_db';
mysql_connect($host, $user, $password);
mysql_select_db($dbname) or die ("Non riesco a selezionare il database");
// qui definisco il file pdf
class PDF extends FPDF
{
//Page intestazione
function Header()
{
//Logo
$this->Image('logo.png',180,8,15);
//Arial bold 15
# $this->SetFont('Arial','B',15);
# //Move to the right
# $this->Cell(80, 10);
# //Title
# $this->Cell(30,10,'Title',1,0,'C');
//Line break
$this->Ln(20);
}
function tabella($titolo, $dtl, $ng, $imp, $fm)
{
$this->SetFont('Arial','B',8);
$this->Cell(60,7,$titolo,1,0,'C');
$this->Ln(7);
$this->SetFont('Arial','B',8);
$this->Cell(15,5,'DTL',1,0,'C');
$this->Cell(15,5,'N.Guasti',1,0,'C');
$this->Cell(15,5,'Impostato',1,0,'C');
$this->Cell(15,5,'Fermo m.',1,0,'C');
$this->Ln(5);
$this->Cell(15,5,$dtl.'%',1,0,'C');
$this->Cell(15,5,$ng,1,0,'C');
$this->Cell(15,5,$imp.' h.',1,0,'C');
$this->Cell(15,5,$fm.' h.',1,0,'C');
$this->Ln(5);
}
}
//qui creo la prima parte del pdf senza valori da db
$pdf=new PDF("P", "mm", "A4");
$pdf->open();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(0,0,'RISULTATI DI CALCOLO DELLA DTL',0,1,'C');
$pdf->Ln(10);
$pdf->Cell(60,0,'Unità produttiva',0,0,'C');
$pdf->Cell(60,0,'Sistema prod.',0,0,'C');
$pdf->Cell(60,0,'macchina',0,0,'C');
$pdf->Ln(10);
//seleziono i dati dal db
$macfine = mysql_query("SELECT * from dtl ") or die("Query non valida: " . mysql_error());
while ($row = mysql_fetch_array($macfine))
{$pdf->tabella($row[1],$row['dtl'],$row['n_g'],'-','-');
}
//fine della creazione del file pdf
$pdf->Output("./storico/".$_POST['filename'].".pdf");
$pdf->close();
Spero che sia chiaro...