Jump to content
Fórum Script Brasil
  • 0

FPDF


mauror
 Share

Question

Após conexão ao banco de dados, tenho o seguinte código:


$result=mysql_query("select id,nome,raca from $tabela where raca='girol' ORDER BY nome");
//$number_of_products = mysql_numrows($result);

//Initialize the 3 columns and the total
$column_code = "";
$column_nome = "";
$column_raca = "";
$total = 0;

//For each row, add the field to the corresponding column
while($row = mysql_fetch_array($result))
{
    $code = $row["id"];
    $name = $row["nome"];
    $raca = $row["raca"];

    $column_code = $column_code.$code."\n";
    $column_nome = $column_nome.$name."\n";
    $column_raca = $column_raca.$raca."\n";

    //Sum all the Prices (TOTAL)
//    $total = $total+$real_price;
}
mysql_close();

//Create a new PDF file
$pdf=new FPDF();
$pdf->AddPage();

function GetPageHeight()
{
    // Get current page height
    return $pdf->h;
}

//////////////////////////////
// numeração da pagina
/////////////////////////////

// Arial italic 8
$pdf->SetFont('Arial','I',12);
// Text color in gray
$pdf->SetTextColor(0);
// Page number
$pdf->Cell(0,10,'Página '.$pdf->PageNo(),0,0,'C');


//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,'id',1,0,'L',1);

$pdf->SetX(65);
$pdf->Cell(70,6,'nome',1,0,'L',1);

$pdf->SetX(135);
$pdf->Cell(30,6,'raca',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); // 20 = comprimento da linha 6 = altura da linha

$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
$pdf->MultiCell(70,6,$column_nome,1);

$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$column_raca,1);

$pdf->Output();

O problema é que, quando tenho algumas dezenas de resultados na query, os dados ficam desalinhados.:

A segunda coluna ('nome') só aparece após a listagem da primeira coluna ('id'). A terceira coluna ('raca') só aparece após a listagem das colunas 'id' e 'nome'.

Quando tenho poucos dados, tudo funciona corretamente, aparecendo 'id', 'nome' e 'raça'  na mesma linha, em suas respectivas colunas..

Alguém pode ajudar-me ?

Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      149.6k
    • Total Posts
      646.2k
×
×
  • Create New...