codice:
<?php
//SHOW A DATABASE ON A PDF FILE
//FILE CREATED BY: Carlos José Vásquez Sáez
//YOU CAN CONTACT ME: carlos@magallaneslibre.com
//FROM PUNTA ARENAS, MAGALLANES
define('FPDF_FONTPATH', 'font/');
require('fpdf.php');
//Connect to your database
require_once('../Connections/db_comm.php');
//Select the Products you want to show in your PDF file
mysql_select_db($database_db_comm, $db_comm);
$query_links = "SELECT nome,link,id_link FROM links ORDER BY id_link ASC";
$links = mysql_query($query_links, $db_comm) or die(mysql_error());
$totalRows_links = mysql_num_rows($links);
//Initialize the 3 columns and the total
$column_id = "";
$column_nome = "";
$column_link = "";
$column_id_link = "";
//For each row, add the field to the corresponding column
while($row_links = mysql_fetch_array($links))
{
$id = $row_links["id_link"];
$nome = $row_links["nome"];
$link = $row_links["link"];
$id_link = $row_links["id_link"];
$column_id = $column_id.$id."\n";
$column_nome = $column_nome.$nome."\n";
$column_link = $column_link.$link."\n";
$column_id_link = $column_id_link.$id_link."\n";
}
mysql_close();
//Convert the Total Price to a number with (.) for thousands, and (, ) for decimals.
//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', 9);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(45);
$pdf->Cell(20, 6, 'Id', 1, 0, 'L', 1);
$pdf->SetX(65);
$pdf->Cell(80, 6, 'Nome', 1, 0, 'L', 1);
$pdf->SetX(135);
$pdf->Cell(30, 6, 'Link', 1, 0, 'R', 1);
$pdf->Ln();
$pdf->SetX(170);
$pdf->Cell(30, 6, 'Id_link', 1, 0, 'R', 1);
$pdf->Ln();
//Now show the 3 columns
$pdf->SetFont('Arial', '', 9);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(45);
$pdf->MultiCell(20, 6, $column_id, 1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(80, 6, $column_nome, 1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30, 6, $column_link, 1, 'R');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(170);
$pdf->MultiCell(30, 6, $column_id_link, 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 < $totalRows_links)
{
$pdf->SetX(45);
$pdf->MultiCell(120, 6, '', 1);
$i = $i +1;
}
$pdf->Output();
?>