zebmckey
29-03-2018, 15:15
Buongiorno a tutti,
vorrei scrivere il risultato di una query su di un pdf ma non riesco a fargli vedere le variabili. Vi allego il file php per farvi capire meglio:
<?php
session_start ();
require_once ('../conf/conf.php');
require_once('../tcpdf_include.php');
$con = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!isset($_GET['stampa']))
{
die ("Error, ID selezionato inesistente");
}
$idcorso=addslashes(htmlspecialchars($_GET['stampa']));
$data = "SELECT idcorso,grado,cognome,nome,reparto,corso,header,data_inizio,data_fine,data_esame,giudizio,superato,voto,email FROM persg,gradi,bcorsi,tipo_corso
WHERE persg.idgrado=gradi.idgrado AND bcorsi.user=persg.idpersinsp AND bcorsi.tipo_corso=tipo_corso.idtipocorso AND tipo_corso.idtipocorso=tipo_corso.header AND bcorsi.idcorso=$idcorso;";
$result = mysqli_query($con,$data);
if(!$result)
{
die("Database query failed: " . mysqli_error());
}
while ($row = mysqli_fetch_array($result))
{
$id=$row["idcorso"];
$grado=$row["grado"];
$cognome=$row["cognome"];
$nome=$row["nome"];
$reparto=$row["reparto"];
$email=$row["email"];
$corso=$row["corso"];
$header=$row["header"];
$data_inizio=$row["data_inizio"];
$data_fine=$row["data_fine"];
$data_esame=$row["data_esame"];
$superato=$row["superato"];
$giudizio=$row["giudizio"];
$voto=$row["voto"];
}
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// get the current page break margin
$bMargin = $this->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $this->AutoPageBreak;
// disable auto-page-break
$this->SetAutoPageBreak(false, 0);
// set bacground image
$img_file = K_PATH_IMAGES.'Immagine1.jpg';
$this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
$this->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$this->setPageMark();
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Autore ');
$pdf->SetTitle('Attestato');
$pdf->SetSubject('Corsi');
$pdf->SetKeywords('TCPDF, PDF, corsi');
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
// remove default footer
$pdf->setPrintFooter(false);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/ita.php')) {
require_once(dirname(__FILE__).'/lang/ita.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
//$pdf->SetFont('times', '', 12);
// add a page
$pdf->AddPage();
// Print a text
$pdf->SetFont('times', '', 24);
$html = <<<EOT
'<h1 style="text-align: center;"><strong>ATTESTATO DI FORMAZIONE</strong></h1>
<h3 style="text-align: center;"><em><strong> $header si attesta che il </strong></em></h3>
<h2 style="text-align: center;"><strong> $grado $cognome $nome </strong></h2>'
EOT;
$pdf->writeHTML($html, true, false, true, false, '');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('corso.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
?>
nelaa variabile $html non mi vede le variabili $header, $grado, $cognome e $nome.
Come posso risolvere?
Grazie
vorrei scrivere il risultato di una query su di un pdf ma non riesco a fargli vedere le variabili. Vi allego il file php per farvi capire meglio:
<?php
session_start ();
require_once ('../conf/conf.php');
require_once('../tcpdf_include.php');
$con = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!isset($_GET['stampa']))
{
die ("Error, ID selezionato inesistente");
}
$idcorso=addslashes(htmlspecialchars($_GET['stampa']));
$data = "SELECT idcorso,grado,cognome,nome,reparto,corso,header,data_inizio,data_fine,data_esame,giudizio,superato,voto,email FROM persg,gradi,bcorsi,tipo_corso
WHERE persg.idgrado=gradi.idgrado AND bcorsi.user=persg.idpersinsp AND bcorsi.tipo_corso=tipo_corso.idtipocorso AND tipo_corso.idtipocorso=tipo_corso.header AND bcorsi.idcorso=$idcorso;";
$result = mysqli_query($con,$data);
if(!$result)
{
die("Database query failed: " . mysqli_error());
}
while ($row = mysqli_fetch_array($result))
{
$id=$row["idcorso"];
$grado=$row["grado"];
$cognome=$row["cognome"];
$nome=$row["nome"];
$reparto=$row["reparto"];
$email=$row["email"];
$corso=$row["corso"];
$header=$row["header"];
$data_inizio=$row["data_inizio"];
$data_fine=$row["data_fine"];
$data_esame=$row["data_esame"];
$superato=$row["superato"];
$giudizio=$row["giudizio"];
$voto=$row["voto"];
}
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// get the current page break margin
$bMargin = $this->getBreakMargin();
// get current auto-page-break mode
$auto_page_break = $this->AutoPageBreak;
// disable auto-page-break
$this->SetAutoPageBreak(false, 0);
// set bacground image
$img_file = K_PATH_IMAGES.'Immagine1.jpg';
$this->Image($img_file, 0, 0, 210, 297, '', '', '', false, 300, '', false, false, 0);
// restore auto-page-break status
$this->SetAutoPageBreak($auto_page_break, $bMargin);
// set the starting point for the page content
$this->setPageMark();
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Autore ');
$pdf->SetTitle('Attestato');
$pdf->SetSubject('Corsi');
$pdf->SetKeywords('TCPDF, PDF, corsi');
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(0);
$pdf->SetFooterMargin(0);
// remove default footer
$pdf->setPrintFooter(false);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/ita.php')) {
require_once(dirname(__FILE__).'/lang/ita.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
//$pdf->SetFont('times', '', 12);
// add a page
$pdf->AddPage();
// Print a text
$pdf->SetFont('times', '', 24);
$html = <<<EOT
'<h1 style="text-align: center;"><strong>ATTESTATO DI FORMAZIONE</strong></h1>
<h3 style="text-align: center;"><em><strong> $header si attesta che il </strong></em></h3>
<h2 style="text-align: center;"><strong> $grado $cognome $nome </strong></h2>'
EOT;
$pdf->writeHTML($html, true, false, true, false, '');
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('corso.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
?>
nelaa variabile $html non mi vede le variabili $header, $grado, $cognome e $nome.
Come posso risolvere?
Grazie