Foros del Web » Programando para Internet » PHP »

problemas con la clase FPDF

Estas en el tema de problemas con la clase FPDF en el foro de PHP en Foros del Web. Me explico tengo dos tablas una de familias otra de articulos , los articulos corresponden a una familia correspondiente , programe utilizando la clase FPDF ...
  #1 (permalink)  
Antiguo 03/07/2012, 09:50
 
Fecha de Ingreso: abril-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
problemas con la clase FPDF

Me explico tengo dos tablas una de familias otra de articulos , los articulos corresponden a una familia correspondiente , programe utilizando la clase FPDF para ficheros .pdf
El problema es que el pdf me muestra solo la ultima familia y sus articulos y no todas las familias y sus articulos

Codigo:

Código:
<?php

require('fpdf/fpdf.php');
require('funciones/conexion.php');
class PDF extends FPDF
{
var $widths;
var $aligns;

function SetWidths($w)
{
	//Set the array of column widths
	$this->widths=$w;
}

function SetAligns($a)
{
	//Set the array of column alignments
	$this->aligns=$a;
}

function Row($data)
{
	//Calculate the height of the row
	$nb=0;
	for($i=0;$i<count($data);$i++)
		$nb=max($nb,$this->NbLines($this->widths[$i],$data[$i]));
	$h=5*$nb;
	//Issue a page break first if needed
	$this->CheckPageBreak($h);
	//Draw the cells of the row
	for($i=0;$i<count($data);$i++)
	{
		$w=$this->widths[$i];
		$a=isset($this->aligns[$i]) ? $this->aligns[$i] : 'L';
		//Save the current position
		$x=$this->GetX();
		$y=$this->GetY();
		//Draw the border
		
		$this->Rect($x,$y,$w,$h);

		$this->MultiCell($w,5,$data[$i],1,$a,'true');
		//Put the position to the right of the cell
		$this->SetXY($x+$w,$y);
	}
	//Go to the next line
	$this->Ln($h);
}

function CheckPageBreak($h)
{
	//If the height h would cause an overflow, add a new page immediately
	if($this->GetY()+$h>$this->PageBreakTrigger)
		$this->AddPage($this->CurOrientation);
}

function NbLines($w,$txt)
{
	//Computes the number of lines a MultiCell of width w will take
	$cw=&$this->CurrentFont['cw'];
	if($w==0)
		$w=$this->w-$this->rMargin-$this->x;
	$wmax=($w-2*$this->cMargin)*1000/$this->FontSize;
	$s=str_replace("\r",'',$txt);
	$nb=strlen($s);
	if($nb>0 and $s[$nb-1]=="\n")
		$nb--;
	$sep=-1;
	$i=0;
	$j=0;
	$l=0;
	$nl=1;
	while($i<$nb)
	{
		$c=$s[$i];
		if($c=="\n")
		{
			$i++;
			$sep=-1;
			$j=$i;
			$l=0;
			$nl++;
			continue;
		}
		if($c==' ')
			$sep=$i;
		$l+=$cw[$c];
		if($l>$wmax)
		{
			if($sep==-1)
			{
				if($i==$j)
					$i++;
			}
			else
				$i=$sep+1;
			$sep=-1;
			$j=$i;
			$l=0;
			$nl++;
		}
		else
			$i++;
	}
	return $nl;
}

function Header()
{

	$this->SetFont('Arial','',10);
	$this->Text(20,14,'Lista de Articulos',0,'C', 0);
	$this->Ln(2);
}

function Footer()
{
	$this->SetY(-15);
	$this->SetFont('Arial','B',8);
	$this->Cell(100,10,'Articulos',0,0,'L');

}

}
	$link =  Conectarse();	
	$queryfamilias="SELECT familia.codigo, familia.descripcion
							FROM
							familia
 							ORDER BY `descripcion` ASC ";
							
	$result=mysql_query($queryfamilias,$link);
	$nufilas = mysql_num_rows($result);
	for ($i2=0; $i2<$nufilas; $i2++)
		{
	$row=mysql_fetch_array($result);
	
	$familia=$row['codigo'];
	
	$strConsulta = "SELECT
							familia.codigo,
							familia.descripcion
							FROM
							familia where codigo =  '$familia'";
	
	$subFamilia = mysql_query($strConsulta,$link);
	
	$fila = mysql_fetch_array($subFamilia);

	$pdf=new PDF('P','mm','Letter');
	$pdf->Open();
	$pdf->AddPage();
	$pdf->SetMargins(20,20,20);
	$pdf->Ln(4);

    $pdf->SetFont('Arial','B',9);
    $pdf->Cell(0,6,'Familia: '.$fila['descripcion'],0,1);
	
	
	$pdf->Ln(10);
	
	$pdf->SetWidths(array(20, 60, 30, 20, 45));
	$pdf->SetFont('Arial','B',10);
	$pdf->SetFillColor(255,255,255);
    $pdf->SetTextColor(0);

		for($i=0;$i<1;$i++)
			{
				$pdf->Row(array('Codigo', 'Descripcion', 'Uni. Med.','Uni. Env.','Ubicacion Bodega' ));
			}
	
		
	$strConsulta = "SELECT
articulo.codigo,
articulo.descripcion,
articulo.unidad_medida,
articulo.ubicacion_bodega,
articulo.unidad_envase
FROM
articulo where articulo.familia_codigo = '$familia'";
	
	$historial = mysql_query($strConsulta,$link);
	$numfilas = mysql_num_rows($historial);
	
	for ($i=0; $i<$numfilas; $i++)
		{
			$fila = mysql_fetch_array($historial);
			$pdf->SetFont('Arial','',8);
			
			if($i%2 == 1)
			{
				$pdf->SetFillColor(255,255,255);
    			$pdf->SetTextColor(0);
				$pdf->Row(array($fila['codigo'], $fila['descripcion'], $fila['unidad_medida'],$fila['unidad_envase'], $fila['unidad_envase']));
			}
			else
			{
				$pdf->SetFillColor(204,204,204);
    			$pdf->SetTextColor(0);
				$pdf->Row(array($fila['codigo'], $fila['descripcion'], $fila['unidad_medida'],$fila['unidad_envase'] ,$fila['ubicacion_bodega']));
			}
		}
		
		}
$pdf->Output();
?>
Ayuda porfavor
  #2 (permalink)  
Antiguo 03/07/2012, 10:14
 
Fecha de Ingreso: abril-2012
Mensajes: 17
Antigüedad: 12 años
Puntos: 0
Respuesta: problemas con la clase FPDF

Ya pille el error tenia que quitar el
$pdf=new PDF('P','mm','Letter');
Dentro de For pero ahora como podría mostrar 2 listas de artículos mientras la hoja no se acabe?

Etiquetas: clase, fpdf, mysql, sql, tabla
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 00:26.