<?php
/* Database credentials. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
//session_start();
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'pcc_ejemplo');
define('DB_PASSWORD', 'xzcreqrqd');
define('DB_NAME', 'pcc_Gest);
/* Attempt to connect to MySQL database */
$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
?>
<?php
require 'fpdf/fpdf.php';
class PDF extends FPDF
{
//cabecera de página
function Header()
{
//logo
//$this->image('logo.png',10,8,33);
//arial bold 15
$this->SentFont('Arial','B',18);
//Movernos a la derecha
$this>Cell(50);
//Título
$this->Cell(70,10,'Reporte de Empleados',0,0,'C');
//Salto de línea
$this->Ln(20);
$this->Cell(20,10,'id',1,0,'C',0);
$this->Cell(40,10,'name',1,0,'C',0);
$this->Cell(40,10,'adreess',1,0,'C',0);
$this->Cell(20,10,'salary',1,1,'C',0);
}
//Pie de Página
function Footer()
{
//Posición:a 1,5 cm del final
$this->SetY(-15);
// Arial italic 8
$this->SentFont('Arial','I',8);
//Número de página
$this->Cell(0,10,utf8_decode('Página').$this->PageNo().'/{nb}',0,0,'C');
}
}
require 'config.php';
$sql='SELECT * FROM employees';
$result = $link->query($sql);
//$pdf = new PDF();
$pdf->AliasNbPages(); *****AQUI DA EL ERROR (LINEA 39) SI LO ANULO CON // SIGUE EL ERROR CON LINEA 40
$pdf->AddPage();
////$pdf->SetFont("Arial","",30);
//$pdf->SetFont('Arial','',16);
// si pongo 'B'es negrita
while($row=$result->fetch_assoc()){
//C centrado
$pdf->Cell(20,10,$row['id'],1,0,'C',0);
$pdf->Cell(40,10,$row['name'],1,0,'C',0);
$pdf->Cell(40,10,$row['adreess'],1,0,'C',0);
$pdf->Cell(20,10,$row['salary'],1,1,'C',0);
//1 en la última fila para salto de linea en la cuarta columna
}
//$pdf->SetY(10);
//$pdf->SetX(5);
//$pdf->Cell(40,10,utf8decode ('Hola, Mundo FPDF con PHP!'));
$pdf->output();
?>
<?php
require 'fpdf/fpdf.php';
class PDF extends FPDF
{
//cabecera de página
function Header()
{
//logo
//$this->image('logo.png',10,8,33);
//arial bold 15
$this->SentFont('Arial','B',18); ......AQUI ME DA ERROR (LINEA 11)....
//Movernos a la derecha
$this>Cell(50);
//Título
$this->Cell(70,10,'Reporte de Empleados',0,0,'C');
//Salto de línea
$this->Ln(20);
$this->Cell(20,10,'id',1,0,'C',0);
$this->Cell(40,10,'name',1,0,'C',0);
$this->Cell(40,10,'adreess',1,0,'C',0);
$this->Cell(20,10,'salary',1,1,'C',0);
}
//Pie de Página
function Footer()
{
//Posición:a 1,5 cm del final
$this->SetY(-15);
// Arial italic 8
$this->SentFont('Arial','I',8);
//Número de página
$this->Cell(0,10,utf8_decode('Página').$this->PageNo().'/{nb}',0,0,'C');
}
}
require 'config.php';
$sql='SELECT * FROM employees';
$result = $link->query($sql);
$pdf = new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
////$pdf->SetFont("Arial","",30);
//$pdf->SetFont('Arial','',16);
// si pongo 'B'es negrita
while($row=$result->fetch_assoc()){
//C centrado
$pdf->Cell(20,10,$row['id'],1,0,'C',0);
$pdf->Cell(40,10,$row['name'],1,0,'C',0);
$pdf->Cell(40,10,$row['adreess'],1,0,'C',0);
$pdf->Cell(20,10,$row['salary'],1,1,'C',0);
//1 en la última fila para salto de linea en la cuarta columna
}
//$pdf->SetY(10);
//$pdf->SetX(5);
//$pdf->Cell(40,10,utf8decode ('Hola, Mundo FPDF con PHP!'));
$pdf->output();
$pdf->Cell(20,10,$row['id'],1,0,'C',0);
$pdf->Cell(20,10, 'id', 1,0,'C',0);
<?php
require 'config.php';
$consulta='SELECT * FROM employees';
$resultado = $link->query($consulta);
require('fpdf/fpdf.php'); //incluimos la libreria.
class PDF extends FPDF {
function tabla($header,$data)
{
//Colores, ancho de línea y fuente en negrita de CABECERA
$this->SetFillColor(255,0,0); // fondo de celda
$this->SetTextColor(255); // color del texto
$this->SetDrawColor(128,0,0); // color de linea
$this->SetLineWidth(.3); // ancho de linea
$this->SetFont('','B'); // negrita
$w=array(20,35,60,70); // en este arreglo definiremos el ancho de cada columna
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',1); //por cada encabezado existente, crea una celda
$this->Ln();
//Colores, ancho de línea y fuente en negrita de CONTENIDO
$this->SetFillColor(224,235,255); //
$this->SetTextColor(0);
$this->SetFont('');
//Datos
$fill=false; // variable para alternar relleno
foreach($data as $row)
{
$columna = explode(";",$row); //separar los datos en posiciones de arreglo
$this->Cell($w[0],6,$columna[0],'LR',0,'L',$fill); //celda(ancho,alto,salto de linea,border,alineacion,relleno)
$this->Cell($w[1],6,$columna[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$columna[2],'LR',0,'R',$fill);
$this->Cell($w[3],6,$columna[3],'LR',0,'R',$fill);
$this->Ln();
//$fill=!$fill; //se alterna el valor del boolean $fill para cambiar relleno
}
$this->Cell(array_sum($w),0,'','T');
}
function Footer()
{
//Pie de página
$this->SetY(-15);
$this->SetFont('Arial','I',8);
$this->SetTextColor(128);
$this->Cell(0,10,'Página '.$this->PageNo().' de {nb}',0,0,'C'); // el parametro {nb} es generado por una funcion llamada AliasNbPages
}
}
$pdf = new PDF();
$pdf->AliasNbPages(); //funcion que calcula el numero de paginas
$head = array("ID","NAME","ADDRESS","SALARY"); // cabecera
$pdf->AddPage(); //crear documento
//$pdf->Image('php.gif',10,8,30,30); //añadir imagen
$pdf->Cell(40);
$pdf->SetFont('Arial','',32);
$pdf->Cell(140,30,"Listado de Empleados",0,0,'C');
$pdf->Ln(35);
$pdf->SetFont('Arial','',12);
$pdf->Cell(50,1,"Fecha: ".date("j-m-y"),0,0,'L');
$pdf->Ln(7);
$pdf->tabla($head,$dat);
while($row=$resultado->fetch_assoc()){
$pdf->Cell(20,6,$row['id'],1,0,'C');
//$pdf->Cell(40,6,utf8_decode($row['nombre']),1,0,'C');
$pdf->Cell(40,6,($row['name']),1,0,'C');
$pdf->Cell(50,6,$row['address'],1,0,'C');
$pdf->Cell(60,6,$row['salary'],1,1,'C');
}
$pdf->Output();
?>