Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2001
    Messaggi
    892

    problema con creazione pdf

    Salve a tutti; ho da poco scaricato il materiale per lavorare con fpdf, e mi imbatto in un problema: ho cercato di modificare uno script che mi permette di impaginare i risultati di una query su db mysql.

    Il fatto però è che, al posto di creare un pdf, lui crea una pagina web illeggibile.
    Posto il codice:

    codice:
    <?php
    
    define('FPDF_FONTPATH','font/');
    require('fpdf.php');
    
    //Connect to your database
    $host = 'localhost';
    $user = 'nomeuser';
    $password = 'password';
    $database = 'nomedb';
    $db = mysql_connect($host,$user,$password) or die ("impossibile connettersi al server $host");
    
    mysql_select_db($database, $db) or die ("impossibile connettersi al database $database");
    
    //Select the Products you want to show in your PDF file
    $result=mysql_query("select * from miatabella ORDER BY numero");
    $number_of_products = mysql_numrows($result);
    
    //Initialize the 3 columns and the total
    $column_code = "";
    $column_name = "";
    $column_price = "";
    
    
    //For each row, add the field to the corresponding column
    while($row = mysql_fetch_array($result))
    {
    	$code = $row["numero"];
    	$name = substr($row["oggetto"],0,20);
    	$real_price = $row["id"];
    	
    
    	$column_code = $column_code.$code."\n";
    	$column_name = $column_name.$name."\n";
    	
    
    }
    mysql_close();
    
    
    //Create a new PDF file
    $pdf=new FPDF();
    $pdf->Open();
    $pdf->AddPage();
    
    //Fields Name position
    $Y_Fields_Name_position = 20;
    //Table position, under Fields Name
    $Y_Table_Position = 26;
    
    //First create each Field Name
    //Gray color filling each Field Name box
    $pdf->SetFillColor(232,232,232);
    //Bold Font for Field Name
    $pdf->SetFont('Arial','B',12);
    $pdf->SetY($Y_Fields_Name_position);
    $pdf->SetX(45);
    $pdf->Cell(20,6,'CODE',1,0,'L',1);
    $pdf->SetX(65);
    $pdf->Cell(100,6,'NAME',1,0,'L',1);
    $pdf->SetX(135);
    $pdf->Cell(30,6,'PRICE',1,0,'R',1);
    $pdf->Ln();
    
    //Now show the 3 columns
    $pdf->SetFont('Arial','',12);
    $pdf->SetY($Y_Table_Position);
    $pdf->SetX(45);
    $pdf->MultiCell(20,6,$column_code,1);
    $pdf->SetY($Y_Table_Position);
    $pdf->SetX(65);
    $pdf->MultiCell(100,6,$column_name,1);
    $pdf->SetY($Y_Table_Position);
    $pdf->SetX(135);
    $pdf->MultiCell(30,6,$columna_price,1,'R');
    
    //Create lines (boxes) for each ROW (Product)
    //If you don't use the following code, you don't create the lines separating each row
    $i = 0;
    $pdf->SetY($Y_Table_Position);
    while ($i < $number_of_products)
    {
    	$pdf->SetX(45);
    	$pdf->MultiCell(120,6,'',1);
    	$i = $i +1;
    }
    
    $pdf->Output();
    ?>

  2. #2
    Utente di HTML.it L'avatar di mark2x
    Registrato dal
    Nov 2005
    Messaggi
    1,940
    Prova a salvarlo con:

    codice:
      $pdf->Output("test.pdf");
    e dimmi che vedi.

    [.:: JaguarXF ::.]
    __________________

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    591
    l'errore sembra qui
    $pdf->MultiCell(30,6,$columna_price ,1,'R');
    la variabile si chiama column_price

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.