PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Dec 20, 2014 6:31 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Reports with FPDF.
PostPosted: Fri Dec 10, 2010 7:54 am 
Offline
Forum Commoner

Joined: Sun Aug 29, 2010 5:24 am
Posts: 59
Hi all;
I have devolop a php code by looking at some examples on fpdf. What this does is it imports data from a mysql server onto a pdf. Unfortunatley it dosent appear as i wanted. cells are overlapping each other. Does anyone know how to solve this problem? Please refer my attachments.
Syntax: [ Download ] [ Hide ]
<?php
  require("C:/wamp/www/fpdf.php");

$connect = mysql_connect ("localhost","root","") or die ("error");
mysql_select_db ("guestbook") or die ("eroor connecting Database");
/*

$queryget = mysql_query ("select * from report ORDER BY Transaction_Number DESC LIMIT 5" ) or die (" error with table");*/

$todayDate = date('Y-m-d');
$queryget = mysql_query ("select * from report WHERE Date='".$todayDate."' " ) or die (" error with table");

$number_of_products = mysql_numrows($queryget);

$column_Customername = "";
$column_Transaction = "";
$column_Time = "";
$column_Weight = "";
$column_Price = "";
$column_Date ="";
$total = 0;
$total1=0;


 while ( $row = mysql_fetch_assoc ($queryget) ){
$id = $row['id'];
  $Customername = $row ['Customer_name'];
  $Transaction_Number = $row ['Transaction_Number'];
  $Price = $row ['Price'];
  $Weight = $row ['Weight'];
  $date = $row ['Date'];
  $time = $row ['Time'];
  $column_Customername = $column_Customername.$Customername."\n";
  $column_Transaction = $column_Transaction.$Transaction_Number."\n";
  $column_Time = $column_Time.$time."\n";
  $column_Weight = $column_Weight.$Weight."\n";
  $column_Price = $column_Price.$Price."\n";
  $column_Date = $column_Date.$date."\n";
 
  $total = $total+$Price;
  $total1 = $total1+$Weight;
  }
 

 $pdf=new FPDF();
$pdf->AddPage();

class PDF extends FPDF
{
//Page header
/*
function Header()
{
    //Logo
    $this->Image('trans.jpeg',10,8,160);
    //Arial bold 15
    $this->SetFont('Arial','B',15);
    //Move to the right
    $this->Cell(80);
    //Title
    /*$this->Cell(30,10,'Title',1,0,'C');
    //Line break
    $this->Ln(20);
}*/


//Page footer
function Footer()
{
    //Position at 1.5 cm from bottom
    $this->SetY(-15);
    //Arial italic 8
    $this->SetFont('Arial','I',8);
    //Page number
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
        $this->setX(10);
         $this->Cell(0,10,'Confidential',0,0,'L');
}
}

//Instanciation of inherited class
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont('Times','',12);
/*for($i=1;$i<=40;$i++)
    $pdf->Cell(0,10,'Printing line number '.$i,0,1);*/


$pdf->setX(50);
$pdf->sety(32);
$pdf->cell(25,6,$column_Date);

//Fields Name position
$Y_Fields_Name_position = 40;
//Table position, under Fields Name
$Y_Table_Position = 46;

//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',8);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(30);
$pdf->Cell(25,6,'Trans.Number',1,0,'L',1);
$pdf->SetX(55);
$pdf->Cell(50,6,'Name',1,0,'L',1);
$pdf->SetX(105);
$pdf->Cell(25,6,'Time',1,0,'L',1);
$pdf->SetX(130);
$pdf->Cell(25,6,'Weight',1,0,'L',1);
$pdf->SetX(155);
$pdf->Cell(25,6,'Price',1,0,'L',1);
$pdf->Ln();
//Now show the 3 columns
$pdf->SetFont('Arial','',6);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(30);
$pdf->MultiCell(35,6,$column_Transaction,1,'false');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(55);
$pdf->MultiCell(50,6,$column_Customername,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(105);
$pdf->MultiCell(25,6,$column_Time,1,'R');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(130);
$pdf->MultiCell(25,6,$column_Weight,1,'R');
$pdf->SetX(130);
$pdf->MultiCell(25,6,'Kg '.$total1,1,'R');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(155);
$pdf->MultiCell(25,6,$column_Price,1,'R');
$pdf->SetX(155);
$pdf->MultiCell(25,6,'Rs '.$total,1,'R');

$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();

?>


Attachments:
File comment: please have a look on this
mypdf.jpg
mypdf.jpg [ 63.37 KiB | Viewed 2541 times ]
Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group