Foros del Web » Programando para Internet » PHP »

fpdf y consulta mysql

Estas en el tema de fpdf y consulta mysql en el foro de PHP en Foros del Web. Hola a todos! ;) necesito crear un catologo de libros utilizando fpdf desde una consulta a mysql con php. He intentado usar el codigo fuente ...
  #1 (permalink)  
Antiguo 21/06/2008, 11:10
 
Fecha de Ingreso: junio-2008
Mensajes: 291
Antigüedad: 15 años, 10 meses
Puntos: 9
fpdf y consulta mysql

Hola a todos! ;) necesito crear un catologo de libros utilizando fpdf desde una consulta a mysql con php. He intentado usar el codigo fuente de los ejemplos y hacer querys sin resultado y también algún codigo del foro que se daba por supuesto funcionaba. ¿Alguna idea? El último código utilizado es el siguiente. Gracias por la ayuda.



Código PHP:
<?php

define
('FPDF_FONTPATH','font/');
require(
'fpdf.php');

//Connect to your database
include("conexion.php");

//Create new pdf file
$pdf=new FPDF();

//Disable automatic page break
$pdf->SetAutoPageBreak(false);

//Add first page
$pdf->AddPage();

//set initial y axis position per page
$y_axis_initial 25;

//print column titles for the actual page
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',12);
$pdf->SetY($y_axis_initial);
$pdf->SetX(25);
$pdf->Cell(30,6,'CODI',1,0,'L',1);
$pdf->Cell(100,6,'NOMB',1,0,'L',1);
$pdf->Cell(30,6,'PVP',1,0,'R',1);

$y_axis $y_axis $row_height;

//Select the Products you want to show in your PDF file
$result=@mysql_query('select CODI, NOMB, PVP from vells ORDER BY CODI',$link);

//initialize counter
$i 0;

//Set maximum rows per page
$max 25;

//Set Row Height
$row_height 6;

while(
$row =@mysql_fetch_array($result))
{
    
//If the current row is the last one, create new page and print column title
    
if ($i == $max)
    {
        
$pdf->AddPage();

        
//print column titles for the current page
        
$pdf->SetY($y_axis_initial);
        
$pdf->SetX(25);
        
$pdf->Cell(30,6,'CODI',1,0,'L',1);
        
$pdf->Cell(100,6,'NOMB',1,0,'L',1);
        
$pdf->Cell(30,6,'PVP',1,0,'R',1);
        
        
//Go to next row
        
$y_axis $y_axis $row_height;
        
        
//Set $i variable to 0 (first row)
        
$i 0;
    }

    
$CODI $row['CODI'];
    
$PVP $row['PVP'];
    
$NOMB $row['CODI'];

    
$pdf->SetY($y_axis);
    
$pdf->SetX(25);
    
$pdf->Cell(30,6,$CODI,1,0,'L',1);
    
$pdf->Cell(100,6,$NOMB,1,0,'L',1);
    
$pdf->Cell(30,6,$PVP,1,0,'R',1);

    
//Go to next row
    
$y_axis $y_axis $row_height;
    
$i $i 1;
}

mysql_close($conexion);

//Create file
$pdf->Output();
?>
  #2 (permalink)  
Antiguo 21/06/2008, 11:14
Avatar de johnj  
Fecha de Ingreso: marzo-2007
Mensajes: 65
Antigüedad: 17 años, 1 mes
Puntos: 0
Respuesta: fpdf y consulta mysql

Pero que es lo que pasa más exactamente...te sale algún error y que error es??
  #3 (permalink)  
Antiguo 21/06/2008, 11:26
 
Fecha de Ingreso: junio-2008
Mensajes: 291
Antigüedad: 15 años, 10 meses
Puntos: 9
Respuesta: fpdf y consulta mysql

Hola. Gracias pot el interés. Me muestra el título de las columnas pero no los resultados.
  #4 (permalink)  
Antiguo 21/06/2008, 19:02
Avatar de jaronu  
Fecha de Ingreso: febrero-2008
Mensajes: 2.183
Antigüedad: 16 años, 2 meses
Puntos: 52
Respuesta: fpdf y consulta mysql

Hola

mira aver de quitarle la arroba a

while($row =@mysql_fetch_array($result))

a ver si te tira error

while($row =mysql_fetch_array($result))

Un saludo
  #5 (permalink)  
Antiguo 23/06/2008, 08:26
 
Fecha de Ingreso: junio-2008
Mensajes: 291
Antigüedad: 15 años, 10 meses
Puntos: 9
Respuesta: fpdf y consulta mysql

Hola! resuelto. Aporto codigo. Gracias a todos! ;)

<?php

define('FPDF_FONTPATH','font/');
require('fpdf.php');

//Conexion a la bd
include("conexion.php");

//Crea un nuevo pdf
$pdf=new FPDF();

//Disable automatic page break
$pdf->SetAutoPageBreak(true);

//Añade primera página
$pdf->AddPage();

//seteo inicial de margenes y position axis pr pagina
$y_axis_initial = 0;
$x_axis = 10;
$y_axis = 20;

//imprime los titulos de columna para la pagina (quitar comentarios para activar)
$pdf->SetFillColor(232,232,232);
$pdf->SetFont('Arial','B',10);
$pdf->SetY($y_axis_initial);

//$pdf->Cell(30,6,'CODI',1,0,'L',1);


$y_axis = $y_axis + $row_height;

//Hago una query a mi bd
$result=@mysql_query('select CODI, NOMB, LIBRE from vells',$conexion);

//inicializo el contador
$i = 0;

//Seto el maximo de filas por pagina
$max = 25;

//Seteo la altuira de la fila
$row_height = 6;

while($row =@mysql_fetch_array($result))
{
//Si la fila actual es la ultima, creo una nueva página e imprimo el titulo (quitar comentarios para activar)
if ($i == $max)
{
$pdf->AddPage();

//print column titles for the current page
//$pdf->SetY($y_axis_initial);
//$pdf->SetX(25);
//$pdf->Cell(30,6,'CODI',1,0,'L',1);


//Go to next row
$y_axis = $y_axis + $row_height;

//Set $i variable to 0 (first row)
$i = 0;
}

$CODI = $row['CODI'];
$NOMB = $row['NOMB'];
$LIBRE = $row['LIBRE'];

$pdf->SetY($y_axis);
$pdf->SetX($x_axis);
$linea=$CODI.$NOMB.$LIBRE;
$pdf->MultiCell(0,6,$linea,0,1,'L',10);
//$pdf->MultiCell(30,6,$CODI,0,0,'L',0);
//$pdf->MultiCell(90,6,$NOMB,0,0,'Ln',0);
//$pdf->MultiCell(120,6,$LIBRE,0,0,'Ln',0);


//Go to next row
$y_axis = $y_axis + $row_height;
$i = $i + 1;
}

mysql_close($conexion);

//Create file
$pdf->Output();
?>
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.
Tema Cerrado




La zona horaria es GMT -6. Ahora son las 10:53.