Not all cells in FPDF showing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gwenne Moses
    New Member
    • Sep 2011
    • 7

    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...
    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!!!
    :-)
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    The first thing you should do is check that your $fromdata array is being populated correctly.

    Comment

    • Gwenne Moses
      New Member
      • Sep 2011
      • 7

      #3
      @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. :-(

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        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?

        Comment

        • Gwenne Moses
          New Member
          • Sep 2011
          • 7

          #5
          Hello sir.I have fixed the problem couple of weeks ago. Am sorry, I forgot to post it.Really sorry.
          Tnx a lot. :-D

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Can you post your solution? That way someone else who comes across the same problem can benefit from your solution.

            Comment

            Working...