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... -
<?php
-
//connection
-
include "config.php";
-
-
-
$contents="";
-
-
//Mysql query to get records from database
-
-
$user_query = mysql_query('SELECT * FROM CMS');
-
//While loop to fetch the records
-
while($row = mysql_fetch_array($user_query))
-
{
-
$contents.=$row['ID'].",";
-
$contents.=$row['name'].",";
-
$contents.=$row['amount'].",";
-
$contents.=$row['date']." ";
-
}
-
-
-
$contents = strip_tags($contents);
-
-
-
require('fpdf.php');
-
-
class PDF extends FPDF
-
{
-
// Load data
-
function LoadData($contents)
-
{
-
$data = array();
-
$fromdata= array(array());
-
-
$data[] = explode(',',trim($contents));
-
-
$i=0;
-
$x=0;
-
foreach ($data as $value)
-
{
-
$fromdata[$i][$x] = $value;
-
$x++;
-
if ($x%4==0)
-
{
-
$i++;
-
$x=0;
-
}
-
}
-
return $fromdata;
-
}
-
// Colored table
-
function FancyTable($header,$fromdata)
-
{
-
// Colors, line width and bold font
-
$this->SetFillColor(255,0,0);
-
$this->SetTextColor(255);
-
$this->SetDrawColor(128,0,0);
-
$this->SetLineWidth(.3);
-
$this->SetFont('','B');
-
// Header
-
$w = array(40, 35, 40, 45);
-
for($i=0;$i<count($header);$i++)
-
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
-
$this->Ln();
-
// Color and font restoration
-
$this->SetFillColor(224,235,255);
-
$this->SetTextColor(0);
-
$this->SetFont('');
-
// Data
-
$fill = false;
-
// foreach($data as $row)
-
-
for($x=0;$x<count($fromdata);$x++){
-
foreach($fromdata[$x] as $row)
-
{
-
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
-
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
-
$this->Cell($w[2],6,$row[2],'LR',0,'R',$fill);
-
$this->Cell($w[3],6,$row[3],'LR',0,'R',$fill);
-
$this->Ln();
-
$fill = !$fill;
-
-
}
-
-
}
-
// Closing line
-
$this->Cell(array_sum($w),0,'','T');
-
-
}
-
}
-
$pdf = new PDF();
-
// Column headings
-
$header = array('ID', 'Name', 'Amount', 'Date');
-
// Data loading
-
$fromdata = $pdf->LoadData($contents);
-
$pdf->SetFont('Arial','',14);
-
$pdf->AddPage();
-
$pdf->FancyTable($header,$fromdata);
-
$pdf->Output();
-
?>
-
PLEASE!
THANK YOU!!!
:-)
5 3981
The first thing you should do is check that your $fromdata array is being populated correctly.
@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. :-(
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?
Hello sir.I have fixed the problem couple of weeks ago. Am sorry, I forgot to post it.Really sorry.
Tnx a lot. :-D
Can you post your solution? That way someone else who comes across the same problem can benefit from your solution.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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.
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |