Ver Mensaje Individual
  #7 (permalink)  
Antiguo 31/10/2010, 12:46
claudio_hbl
 
Fecha de Ingreso: octubre-2006
Ubicación: Valparaiso Chile
Mensajes: 228
Antigüedad: 17 años, 6 meses
Puntos: 0
Respuesta: Ayuda con FPDF

NO, no amigo, muchas gracias por tu ayuda.

No sé como imprimir $res, lo hice con ECHO, pero leí en el foro que no se puede poner echo dentro de las funciones de fpdf, no imprime nada.

Hice lo de tu recomendación, puse la consulta fuera de la function, quedo así.
Código PHP:
Ver original
  1. $pdf=new PDF();
  2. //Títulos de las columnas
  3. $sql='SELECT * FROM empresa';
  4. $res=mysql_query($sql,Conectar::con());
  5.  
  6. while($row=mysql_fetch_assoc($res)){
  7.         $data[]=array($row);
  8. }
  9. //Títulos de las columnas
  10. $header=array('ID Empresa','Nombre','Direccion','Telefono');
  11. $pdf->SetFont('Arial','',14);
  12. $pdf->AddPage();
  13. $pdf->FancyTable($header,$data);
  14. $pdf->Output();
  15. ?>

En total quedo así.
Código PHP:
Ver original
  1. class PDF extends FPDF
  2. {
  3.  
  4.         function FancyTable($header,$data)
  5.         {
  6.                 //Colores, ancho de línea y fuente en negrita
  7.                 $this->SetFillColor(255,0,0);
  8.                 $this->SetTextColor(255);
  9.                 $this->SetDrawColor(128,0,0);
  10.                 $this->SetLineWidth(.3);
  11.                 $this->SetFont('','B');
  12.                 //Cabecera
  13.                 $w=array(40,35,40,45);
  14.                 for($i=0;$i<count($header);$i++)
  15.                         $this->Cell($w[$i],7,$header[$i],1,0,'C',1);
  16.                         $this->Ln();
  17.                         //Restauración de colores y fuentes
  18.                         $this->SetFillColor(224,235,255);
  19.                         $this->SetTextColor(0);
  20.                         $this->SetFont('');
  21.                         //Datos
  22.                         $fill=false;
  23.                        
  24.                         $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
  25.                         $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
  26.                         $this->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
  27.                         $this->Cell($w[3],6,$row[3],'LR',0,'L',$fill);
  28.                         $this->Ln();
  29.                         $fill=!$fill;
  30.         }
  31. }
  32.                 $this->Cell(array_sum($w),0,'','T');
  33. $pdf=new PDF();
  34.  
  35. $sql='SELECT * FROM empresa';
  36. $res=mysql_query($sql,Conectar::con());
  37.  
  38. while($row=mysql_fetch_assoc($res)){
  39.         $data[]=array($row);
  40. }
  41. //Títulos de las columnas
  42. $header=array('ID Empresa','Nombre','Direccion','Telefono');
  43. $pdf->SetFont('Arial','',14);
  44. $pdf->AddPage();
  45. $pdf->FancyTable($header,$data);
  46. $pdf->Output();
  47. ?>
__________________
Un Cordial Saludo
Claudio González Soto
Negocios Online
http;//www.servpcweb.com