473,406 Members | 2,387 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Not all cells in FPDF showing

Hello there,
Pls help me with this.
I want to output data from database(mySql).Output them in pdf form using FPDF (like a report). My problem is that, Not all the data from the db are being outputted. Just a row(4 cells) is showing. I dont know how to fix this anymore. pls help me..am just a newbie...
Here is my code...
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. //connection
  3. include "config.php";
  4.  
  5.  
  6. $contents="";
  7.  
  8. //Mysql query to get records from database
  9.  
  10. $user_query = mysql_query('SELECT * FROM CMS');
  11. //While loop to fetch the records
  12. while($row = mysql_fetch_array($user_query))
  13. {
  14. $contents.=$row['ID'].",";
  15. $contents.=$row['name'].",";
  16. $contents.=$row['amount'].",";
  17. $contents.=$row['date']." ";
  18. }
  19.  
  20.  
  21. $contents = strip_tags($contents); 
  22.  
  23.  
  24. require('fpdf.php');
  25.  
  26. class PDF extends FPDF
  27. {
  28. // Load data
  29. function LoadData($contents)
  30. {  
  31.     $data = array();
  32.  $fromdata= array(array());
  33.  
  34.        $data[] = explode(',',trim($contents));
  35.  
  36.         $i=0;
  37.         $x=0;
  38.     foreach ($data as $value)
  39.     {
  40.         $fromdata[$i][$x] = $value;
  41.         $x++;
  42.         if ($x%4==0)
  43.         {
  44.             $i++;
  45.             $x=0;
  46.             }
  47.     }
  48.     return $fromdata;    
  49. }
  50. // Colored table
  51. function FancyTable($header,$fromdata)
  52. {
  53.     // Colors, line width and bold font
  54.     $this->SetFillColor(255,0,0);
  55.     $this->SetTextColor(255);
  56.     $this->SetDrawColor(128,0,0);
  57.     $this->SetLineWidth(.3);
  58.     $this->SetFont('','B');
  59.     // Header
  60.     $w = array(40, 35, 40, 45);
  61.     for($i=0;$i<count($header);$i++)
  62.         $this->Cell($w[$i],7,$header[$i],1,0,'C',true);
  63.     $this->Ln();
  64.     // Color and font restoration
  65.     $this->SetFillColor(224,235,255);
  66.     $this->SetTextColor(0);
  67.     $this->SetFont('');
  68.     // Data
  69.     $fill = false;
  70.   //  foreach($data as $row)
  71.  
  72.   for($x=0;$x<count($fromdata);$x++){
  73.         foreach($fromdata[$x] as $row)
  74.     {
  75.         $this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
  76.         $this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
  77.         $this->Cell($w[2],6,$row[2],'LR',0,'R',$fill);
  78.         $this->Cell($w[3],6,$row[3],'LR',0,'R',$fill);
  79.         $this->Ln();
  80.         $fill = !$fill;
  81.  
  82.     }
  83.  
  84.   }
  85.     // Closing line
  86.     $this->Cell(array_sum($w),0,'','T');
  87.  
  88. }
  89. }
  90. $pdf = new PDF();
  91. // Column headings
  92. $header = array('ID', 'Name', 'Amount', 'Date');
  93. // Data loading
  94. $fromdata = $pdf->LoadData($contents);
  95. $pdf->SetFont('Arial','',14);
  96. $pdf->AddPage();
  97. $pdf->FancyTable($header,$fromdata);
  98. $pdf->Output();
  99. ?>
  100.  
PLEASE!
THANK YOU!!!
:-)
Jan 27 '13 #1
5 3981
Rabbit
12,516 Expert Mod 8TB
The first thing you should do is check that your $fromdata array is being populated correctly.
Jan 28 '13 #2
@Rabbit,
Yes sir. I knew from the beginning that the two arrays are causing the problem. I have been trying to alter the loops; remove the $fromdata and the like but still won't work.
Arrays and Loops in PHP are a bit weird. This could have been easy using JAVA. :-(
Jan 28 '13 #3
Rabbit
12,516 Expert Mod 8TB
I'm not sure you responded completely to my suggestion. Are you saying the $fromdata array is not populating correctly? What is in the array instead?
Jan 28 '13 #4
Hello sir.I have fixed the problem couple of weeks ago. Am sorry, I forgot to post it.Really sorry.
Tnx a lot. :-D
Feb 18 '13 #5
Rabbit
12,516 Expert Mod 8TB
Can you post your solution? That way someone else who comes across the same problem can benefit from your solution.
Feb 18 '13 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: madeo | last post by:
hi, i'm looking for some script which would export address labels from a mysql db to pdf ... There's an exapmle, but i'm not able to convert it for using with mysql ... can anybody help? THX...
4
by: Phillip T. Murphy | last post by:
Not sure if this is the correct forum, but since FPDF is a PHP script, I thought I would give it a try... I am having a problem getting ANYTHING to print in a header using the FPDF functions. I...
2
by: LordMerlin | last post by:
Hi I'm trying to write a label printing routine, but I'm not being too sucsessful. I'm hoping maybe someone who's used FPDF b4 can help me out? Basically, I want to print labels from a data...
3
by: syam | last post by:
how do i add jpg images into a Cell in pdf . The cells are created by $pdf->Cell function.I never getting the images inside the cell . I am using $pdf->Image() function to display the image.
3
by: K. | last post by:
Hello! Could you be so kind and help me with one problem I have. I would like to put an image into the table while creating PDF file. I use fpdf class (www.fpdf.org). I cannot find any...
0
by: Mihamina (R12y) Rakotomandimby | last post by:
Hi, In http://www.fpdf.de/downloads/addons/3/ we can find a function that tries to predict the number of lines un a multicell. I dont understand the algorithm, variables are also named with...
1
by: Thivya | last post by:
hello, I am using Jpgraphs to generate graphs..i have to display the data for plotting the graphs as well.These results has to be in PDF.hence i used FPDF to generate pdf.. Now i can display the...
6
by: Steve | last post by:
been gleening the user docs for fpdf. there's one simple example for using the image function. i can't seem to get it to work. has anyone else had problems with this, and if so, what did you do to...
5
by: cappieins | last post by:
Hi, i've got a problem using PHP FPDF library to create PDF files send inline to a browser window. The created PDF file opens correctly in the browser (IE 6), but if I want to save it to my...
1
by: Sergei Riaguzov | last post by:
Hi, I'm having problems with fpdf v.1.1 used on the site - it doesn't open all PDFs with setSourceFile it says something about "missing xref headers". So I tried to install a newer fpdf version...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.