Ciao a tutti ragazzi, sto cercando di creare un piccolo tools per la stampa di determinate etichette prese da un DB MySql esportandole in PDF.
Vi elenco il codice qui sotto dove riporto solo il campo "COGNOME" per fare l'esempio ma non funziona:
codice:
<?php require('fpdf.php'); # connessione al db - preleviamo i nostri dati e contiamoli $server = "localhost"; $user = "root"; $pwd = ""; $datab = "rubrica"; $tabella = "tblcontatti"; $link = mysql_connect ($server, $user, $pwd) or die ("Mysql dice: " . mysql_error() . mysql_errno()); $db = mysql_select_db ($datab, $link) or die ("Mysql dice: " . mysql_error()); //Select the Products you want to show in your PDF file $result=mysql_query("select cognome from $tabella where campo2='1'",$link); $number_of_products = mysql_numrows($result); //Initialize the 3 columns and the total $column_cognome = ""; $total = 0; //echo "
<h5>Stamperemo n. $number_of_products etichetta/e <h5></p>"; //For each row, add the field to the corresponding column while($row = mysql_fetch_array($result)) { $cognome = substr($row["Cognome"],0,20); $column_cognome = $column_cognome.$cognome."\n"; //Sum all the Prices (TOTAL) // $total = $total+$real_price; } mysql_close(); //Create a new PDF file $pdf=new FPDF(); $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,'COGNOME',1,0,'L',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_cognome,1); $pdf->SetY($Y_Table_Position); $pdf->SetX(65); //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) { //echo "
<h5>Stamperemo n. $number_of_products etichetta/e <h5></p>"; $pdf->SetX(45); $pdf->MultiCell(120,6,'',1); $i = $i +1; } $pdf->Output(); ?>
Spero in un vostro aiuto...
grazie!