hola buenas tardes en mi proyecto instale una libreria para hacer pdfs con php pero al momento de querer declarar la variable me dice variable indefinida
<?php
require('../fpdf/fpdf.php');
class PDF extends FPDF{
private $conexion;
public function __construct(){
require('conexion.php');
$this->conexion = new conexion();
$this->conexion->conectar();
}
}
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 10);
$pdf->Image('../assests/img/tienda.gif' , 10 ,8, 10 , 13,'GIF');
$pdf->Cell(18, 10, '', 0);
$pdf->Cell(150, 10, 'Store "Aron Imperial"', 0);
$pdf->SetFont('Arial', '', 9);
$pdf->Cell(50, 10, 'Hoy: '.date('d-m-Y').'', 0);
$pdf->Ln(15);
$pdf->SetFont('Arial', 'B', 11);
$pdf->Cell(70, 8, '', 0);
$pdf->Cell(100, 8, 'List product', 0);
$pdf->Ln(23);
$pdf->SetFont('Arial', 'B',8);
$pdf->Cell(15, 8, 'Code', 0);
$pdf->Cell(50, 8, 'Product', 0);
$pdf->Cell(25, 8, 'Price', 0);
$pdf->Cell(25, 8, 'Stock', 0);
$pdf->Ln(8);
$pdf->SetFont('Arial','',8);
$record = $product->query("SELECT * FROM product");
$pdf->Output();
?>
los errores
Notice: Undefined variable: product in C:\xampp\htdocs\store\fpdf\list_product.php on line 32
Fatal error: Call to a member function query() on null in C:\xampp\htdocs\store\fpdf\list_product.php on line 32
aqui hay un ejemplo con sql, cuando invoca esa variable que tienes no definida antes la define conectando a la base de datos
http://phppot.com/php/generate-pdf-from-mysql-data-using-fpdf/
debe ser eso, quizas debas cambiar $this por $product o bien generar una nueva conexión ?
no puedo cambiarla ya que todo el proyecto trabaja en POO y no puedo cambiarla
cuando intento hacer esto
<?php
require('fpdf.php');
class PDF extends FPDF{
private $conexion;
public function __construct(){
require('../models/conexion.php');
$this->conexion = new conexion();
$this->conexion->conectar();
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 10);
$pdf->Image('../assests/img/tienda.gif' , 10 ,8, 10 , 13,'GIF');
$pdf->Cell(18, 10, '', 0);
$pdf->Cell(150, 10, 'Store "Aron Imperial"', 0);
$pdf->SetFont('Arial', '', 9);
$pdf->Cell(50, 10, 'Hoy: '.date('d-m-Y').'', 0);
$pdf->Ln(15);
$pdf->SetFont('Arial', 'B', 11);
$pdf->Cell(70, 8, '', 0);
$pdf->Cell(100, 8, 'List product', 0);
$pdf->Ln(23);
$pdf->SetFont('Arial', 'B',8);
$pdf->Cell(15, 8, 'Code', 0);
$pdf->Cell(50, 8, 'Product', 0);
$pdf->Cell(25, 8, 'Price', 0);
$pdf->Cell(25, 8, 'Stock', 0);
$pdf->Ln(8);
$pdf->SetFont('Arial','',8);
$pdf->Output();
?>
me esta esto otro error
Warning: in_array() expects parameter 2 to be array, null given in C:\xampp\htdocs\store\fpdf\fpdf.php on line 501
Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Undefined font: helvetica ' in C:\xampp\htdocs\store\fpdf\fpdf.php:271 Stack trace: #0 C:\xampp\htdocs\store\fpdf\fpdf.php(510): FPDF->Error('Undefined font:...') #1 C:\xampp\htdocs\store\fpdf\list_product.php(14): FPDF->SetFont('Arial', '', 10) #2 {main} thrown in C:\xampp\htdocs\store\fpdf\fpdf.php on line 271
ahora si me deja acceder pero ahora query no puedo usarlo porque dice que no esta definido Fatal error: Call to undefined method PDF::query() in C:\xampp\htdocs\store\fpdf\list_product.php on line 33
<?php
require('fpdf.php');
class PDF extends FPDF{
private $conexion;
public function __construct(){
require('../models/conexion.php');
$this->conexion = new conexion();
$this->conexion->conectar();
parent::__construct();
}
}
$pdf = new PDF();
$pdf->AddPage();
$pdf->SetFont('Arial', '', 10);
$pdf->Image('../assests/img/tienda.gif' , 10 ,8, 10 , 13,'GIF');
$pdf->Cell(18, 10, '', 0);
$pdf->Cell(150, 10, 'Store "Aron Imperial"', 0);
$pdf->SetFont('Arial', '', 9);
$pdf->Cell(50, 10, 'Hoy: '.date('d-m-Y').'', 0);
$pdf->Ln(15);
$pdf->SetFont('Arial', 'B', 11);
$pdf->Cell(70, 8, '', 0);
$pdf->Cell(100, 8, 'List product', 0);
$pdf->Ln(23);
$pdf->SetFont('Arial', 'B',8);
$pdf->Cell(15, 8, 'Code', 0);
$pdf->Cell(50, 8, 'Product', 0);
$pdf->Cell(25, 8, 'Price', 0);
$pdf->Cell(25, 8, 'Stock', 0);
$pdf->Ln(8);
$pdf->SetFont('Arial','',8);
$pdf->query("SELECT * FROM product");
$pdf->Output();
?>
Te aconsejo que te leas bien los errores antes de continuar. Si pone undefined method es que no existe el método, ya que en este caso debería ser:
$sql_statement = "SELECT user.Host, user.User, user.Password, Select_priv as `Select priv`, Insert_priv as `Insert Priv`, Update_priv as `Update priv`, Delete_priv as `Delete priv`, Create_priv as `Create priv`, Reload_priv as `Reload priv`, Shutdown_priv as `Shutdown priv`, Process_priv as `Process priv`, File_priv as `File priv`, Grant_priv as `Grant priv`, References_priv as `References priv`, Index_priv as `Index priv` FROM user LEFT JOIN tables_priv ON user.User=tables_priv.User ORDER BY user.User" ;
// Generate report
$pdf->mysql_report($sql_statement, false, $attr );
/*!!! Very Important: after having done all the work of
setting up the SQL don't forget to output the PDF else
you just get a blank page !!!*/
$pdf->Output();
El código está extraido de la web oficial de fPDF.
http://www.fpdf.org/en/script/script21.php
Salu2