Foros del Web » Programación para mayores de 30 ;) » Programación General »

Ayuda con tablas en fpdf

Estas en el tema de Ayuda con tablas en fpdf en el foro de Programación General en Foros del Web. Hola amigos, estoy intentando crear una tabla en fpf a traves del siguiente codigo: Cita: <?php include_once "../Modelos/Conexion.class.php"; $db = new Conexion(); $db->conectar(); $lista=$_POST['tipolista'];//capturo del ...
  #1 (permalink)  
Antiguo 03/09/2010, 15:14
Juan Diego
Invitado
 
Mensajes: n/a
Puntos:
Ayuda con tablas en fpdf

Hola amigos, estoy intentando crear una tabla en fpf a traves del siguiente codigo:

Cita:
<?php
include_once "../Modelos/Conexion.class.php";
$db = new Conexion();
$db->conectar();

$lista=$_POST['tipolista'];//capturo del formulario


//ListaItem
$consulista=pg_query("select * from listaitem WHERE tipo='$lista'");
$numfilas=pg_num_rows($consulista);
if($numfilas>0){
$row=pg_fetch_array($consulista);
$codigo=$row['codigo_fk'];
$cantidad=$row['cantidad'];

//Info Item
$consultar=pg_query("select * from item where codigo='$codigo'");

$date = date("d/m/y");

require('../lib/fpdf/fpdf.php');

class PDF extends FPDF
{
//Cabecera de página
function Header()
{
global $date;

$this->Image('../IMG/escudocolegioG.JPG' , 100 ,80, 90 , 92,'JPG', '');
$this->SetFont('Arial', 'B', 5);
$this->Cell(122, 15, 'Fecha:', 0, 0, 'R');
$this->Cell(0, 15, $date, 0,1, 'L');
$this->Image('../IMG/escudocolegio.JPG' , 36 ,20, 17 , 19,'JPG', '');

}

function Footer()
{

$this->SetY(-25);

$this->SetFont('Arial','I',8);

$this->Cell(0, 4, 'Carrera 5a No. 12-25 ', 0, 1, 'C');

$this->Cell(0,10,'Pagina '.$this->PageNo().'',0,0,'C');

}

//funcion tabla
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,30,30,20); // 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,'L',$fill);
$this->Cell($w[3],6,$columna[3],'LR',0,'L',$fill);
$this->Cell($w[4],6,$columna[4],'LR',0,'L',$fill);
$this->Cell($w[5],6,$columna[5],'LR',0,'L',$fill);
$this->Cell($w[6],6,$columna[6],'LR',0,'L',$fill);
$this->Cell($w[7],6,$columna[7],'LR',0,'L',$fill);

$this->Ln();
$fill=!$fill; //se alterna el valor del boolean $fill para cambiar relleno
}
$this->Cell(array_sum($w),0,'','T');
}

}

//Creación del objeto de la clase heredada
$pdf=new PDF('L','mm','Letter');
$pdf->SetMargins(23, 19, 9);

//Títulos de las columnas
$head=array('CODIGO','NOMBRE','MARCA','MODELO','SE RIE', 'COLOR', 'ESTADO', 'VALOR');

$i=0;
while ($fila=pg_fetch_array($consultar)){ //llenar variable dat con los campos de una fila unidos por ;
$dat[$i]=$fila[0].";".$fila[1].";".$fila[2].";".$fila[3].";".$fila[4].";".$fila[5].";".$fila[6].";".$fila[7];//concatenar para luego ser separado por explode()
$i++;
}

$pdf->AddPage(); //crear documento
$pdf->tabla($head,$dat);
$pdf->Output(); //el resto es historia

}
else{
echo "<script>alert('EL ITEM NO SE ENCUENTRA EN LA LISTA O EN EL SISTEMA');
window.location='ReporteInvAlta.php';</script>";
}
?>

Cuando tengo las filas en 4:

Cita:
$dat[$i]=$fila[0].";".$fila[1].";".$fila[2].";".$fila[3].";//concatenar para luego ser separado por explode()
El encabezado hasta modelo:
Cita:
$head=array('CODIGO','NOMBRE','MARCA','MODELO');
y las columnas hasta 4 tambien:
Cita:
$this->Cell($w[0],6,$columna[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$columna[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$columna[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$columna[3],'LR',0,'L',$fill);
Me genera el pdf con la tabla con sus valores. Pero cuando lo pongo la tabla con todos los atributos que necesito me muestra el siguiente error y no me genera el pdf.

Cita:
Notice: Undefined offset: 4 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 96

Notice: Undefined offset: 5 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 96

Notice: Undefined offset: 6 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 96

Notice: Undefined offset: 7 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 96

Notice: Undefined offset: 8 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 96

Notice: Undefined offset: 8 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 96

Notice: Undefined offset: 4 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 111

Notice: Undefined offset: 5 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 112

Notice: Undefined offset: 6 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 113

Notice: Undefined offset: 7 in C:\wamp\www\SISMAD\Reportes\ReporteInventario.php on line 114
FPDF error: Some data has already been output, can't send PDF file
segun tengo entendido ese undefined offset porque estoy accediendo a un elemento de un array que no existe. Pero el array si existe y el elemento tambien.

Espero me puedan ayudar, necesito generar la tabla con todos los atributos de la tabla.

Última edición por Juan Diego; 03/09/2010 a las 15:26
  #2 (permalink)  
Antiguo 03/09/2010, 19:56
Juan Diego
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Ayuda con tablas en fpdf

Señores... Buenas tardes...

Les comento que ya solucione el problema, era que no estaba definiendo el ancho de cada columna.

$w=array(20,30,30,20,30,20,30,20);

Gracias... y espero esto le pueda servir a alguien...

Saludos

Etiquetas: fpdf, php, programacion
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:19.