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...
PLEASE!
THANK YOU!!!
:-)
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...
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(); ?>
THANK YOU!!!
:-)
Comment