Link to home
Create AccountLog in
Avatar of eunoiabella
eunoiabella

asked on

How do I create a table in FPDF pulling data out of MYSQL to fill the cells?

I have a table on a php page that allows entry of data into fields in my database. You can see a picture attached below.The entire table has inputs, meaning the top axis, side axis as well as within the table itself.
The table has a list of the same type of variables along the top (y axis) and another list of the same type of variable along the x axis. The ten inputs along the top of the table are entered into the database called competitors:  c1, c2, c3, c4, c5, c6,c7, c8, c9 and c10.
The variables down the left side are entered into mysql as keywords: k1, k2, k3, k4, k5, k6, k7, k8, k9, k10, respectively.
Each input WITHIN the table is called it's keyword number and d1 along to ten, for example:
the first line of inputs in the table is k1d1, k1d2, k1d3, k1d4, k1d5, k and so on along until k1d10
then the next line WITHIN the table is called k2d1 through to k2d10,
the the third line WITHIN the table has it's input fields k3d1 through to k3d10
fourth line k4d1 going accross until k4d10
and so on, with tenth line down of table having it's inputs within the table as k10d1 going accross to k10d10.
 

I want to recreate the table as it is entered in this table exactly into a pdf in FPDF.
So the table needs to call these inputs from the database and position them in the pdf table in exactly the same way.
How do I do this nicely?

Below you will see code for entering inputs into the table in the php page,
and then a picture of the table form for COLLECTING THESE inputs, which is basically the same framework I want to recreate in the pdf,  
then code for a DIFFERENT existing table I would like to copy the aesthetics of.


This is the code for another existing table in my fpdf. For my new table, I'd like to keep the aesthetics the same as this but present the different information above: 
 
case "indexpagestable":
						$cellwidth = ((PAGEWIDTH - (PAGEMARGIN * 2)) * PDF_SCALING) / 6;
						$fontsize = 14;
						$pdf->SetDrawColor(255, 255, 255);
						$pdf->SetFillColor(192, 80, 77);
						$pdf->SetTextColor(255, 255, 255);
						$pdf->Cell($cellwidth * 2, $fontsize, "", 0, 0, "L");
						$pdf->Cell($cellwidth, $fontsize, "Google", 1, 0, "C", true);
						$pdf->Cell($cellwidth, $fontsize, "Yahoo", 1, 0, "C", true);
						$pdf->Cell($cellwidth, $fontsize, "MSN", 1, 1, "C", true);
						$pdf->SetDrawColor(255, 255, 255);
						$pdf->SetFillColor(223, 167, 167);
						$pdf->SetTextColor(0, 0, 0);
						$pdf->Cell($cellwidth, $fontsize, "", 0, 0, "L");
						$pdf->Cell($cellwidth, 14, "Index Pages", 0, 0, "C");
						$pdf->SetTextColor(255, 255, 255);
						$pdf->Cell($cellwidth, $fontsize, $values["googleindexed"], 1, 0, "C", true);
						$pdf->Cell($cellwidth, $fontsize, $values["yahooindexed"], 1, 0, "C", true);
						$pdf->Cell($cellwidth, $fontsize, $values["msnindexed"], 1, 1, "C", true);
						$pdf->SetDrawColor(0, 0, 0);
						$pdf->SetTextColor(0, 0, 0);
						break;
 
 
 
 
And this is the code for collecting the data into the table: 
    <td >Competitors<br /><br />
    Keywords</td>
    
    <td><input value="<?php echo($_POST['c1']); ?>"  type="text" name="c1" /></td>
    <td><input value="<?php echo($_POST['c2']); ?>"  type="text" name="c2" /></td>
    <td><input value="<?php echo($_POST['c3']); ?>"  type="text" name="c3" /></td>
    <td><input value="<?php echo($_POST['c4']); ?>"  type="text" name="c4" /></td>
    <td><input value="<?php echo($_POST['c5']); ?>"  type="text" name="c5" /></td>
    <td><input value="<?php echo($_POST['c6']); ?>"  type="text" name="c6" /></td>
    <td><input value="<?php echo($_POST['c7']); ?>"  type="text" name="c7" /></td>
    <td><input value="<?php echo($_POST['c8']); ?>"  type="text" name="c8" /></td>
    <td><input value="<?php echo($_POST['c9']); ?>"  type="text" name="c9" /></td>
    <td><input value="<?php echo($_POST['c10']); ?>"  type="text" name="c10" /></td>
    
  </tr>
  
  <tr>
    <td width="50"><input value="<?php echo($_POST['k1']); ?>"  type="text" name="k1" id="k1"/></td>
    
    <td><input value="<?php echo($_POST['k1d1']); ?>"  type="text" name="k1d1" /></td>
    <td><input value="<?php echo($_POST['k1d2']); ?>"  type="text" name="k1d2" /></td>
    <td><input value="<?php echo($_POST['k1d3']); ?>"  type="text" name="k1d3" /></td>
    <td><input value="<?php echo($_POST['k1d4']); ?>"  type="text" name="k1d4" /></td>
    <td><input value="<?php echo($_POST['k1d5']); ?>"  type="text" name="k1d5" /></td>
    <td><input value="<?php echo($_POST['k1d6']); ?>"  type="text" name="k1d6" /></td>
    <td><input value="<?php echo($_POST['k1d7']); ?>"  type="text" name="k1d7" /></td>
    <td><input value="<?php echo($_POST['k1d8']); ?>"  type="text" name="k1d8" /></td>
    <td><input value="<?php echo($_POST['k1d9']); ?>"  type="text" name="k1d9" /></td>
    <td><input value="<?php echo($_POST['k1d10']); ?>"  type="text" name="k1d10" /></td>
    
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k2']); ?>"  type="text" name="k2" id="k2"/></td>
    
    <td><input value="<?php echo($_POST['k2d1']); ?>"  type="text" name="k2d1" /></td>
    <td><input value="<?php echo($_POST['k2d2']); ?>"  type="text" name="k2d2" /></td>
    <td><input value="<?php echo($_POST['k2d3']); ?>"  type="text" name="k2d3" /></td>
    <td><input value="<?php echo($_POST['k2d4']); ?>"  type="text" name="k2d4" /></td>
    <td><input value="<?php echo($_POST['k2d5']); ?>"  type="text" name="k2d5" /></td>
    <td><input value="<?php echo($_POST['k2d6']); ?>"  type="text" name="k2d6" /></td>
    <td><input value="<?php echo($_POST['k2d7']); ?>"  type="text" name="k2d7" /></td>
    <td><input value="<?php echo($_POST['k2d8']); ?>"  type="text" name="k2d8" /></td>
    <td><input value="<?php echo($_POST['k2d9']); ?>"  type="text" name="k2d9" /></td>
    <td><input value="<?php echo($_POST['k2d10']); ?>"  type="text" name="k2d10" /></td>
    
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k3']); ?>"  type="text" name="k3" id="k3"/></td>
    
    <td><input value="<?php echo($_POST['k3d1']); ?>"  type="text" name="k3d1" /></td>
    <td><input value="<?php echo($_POST['k3d2']); ?>"  type="text" name="k3d2" /></td>
    <td><input value="<?php echo($_POST['k3d3']); ?>"  type="text" name="k3d3" /></td>
    <td><input value="<?php echo($_POST['k3d4']); ?>"  type="text" name="k3d4" /></td>
    <td><input value="<?php echo($_POST['k3d5']); ?>"  type="text" name="k3d5" /></td>
    <td><input value="<?php echo($_POST['k3d6']); ?>"  type="text" name="k3d6" /></td>
    <td><input value="<?php echo($_POST['k3d7']); ?>"  type="text" name="k3d7" /></td>
    <td><input value="<?php echo($_POST['k3d8']); ?>"  type="text" name="k3d8" /></td>
    <td><input value="<?php echo($_POST['k3d9']); ?>"  type="text" name="k3d9" /></td>
    <td><input value="<?php echo($_POST['k3d10']); ?>"  type="text" name="k3d10" /></td>
    
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k4']); ?>"  type="text" name="k4" id="k4"/></td>
    
    <td><input value="<?php echo($_POST['k4d1']); ?>"  type="text" name="k4d1" /></td>
    <td><input value="<?php echo($_POST['k4d2']); ?>"  type="text" name="k4d2" /></td>
    <td><input value="<?php echo($_POST['k4d3']); ?>"  type="text" name="k4d3" /></td>
    <td><input value="<?php echo($_POST['k4d4']); ?>"  type="text" name="k4d4" /></td>
    <td><input value="<?php echo($_POST['k4d5']); ?>"  type="text" name="k4d5" /></td>
    <td><input value="<?php echo($_POST['k4d6']); ?>"  type="text" name="k4d6" /></td>
    <td><input value="<?php echo($_POST['k4d7']); ?>"  type="text" name="k4d7" /></td>
    <td><input value="<?php echo($_POST['k4d8']); ?>"  type="text" name="k4d8" /></td>
    <td><input value="<?php echo($_POST['k4d9']); ?>"  type="text" name="k4d9" /></td>
    <td><input value="<?php echo($_POST['k4d10']); ?>"  type="text" name="k4d10" /></td>
    
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k5']); ?>"  type="text" name="k5" id="k5"/></td>
    
    <td><input value="<?php echo($_POST['k5d1']); ?>"  type="text" name="k5d1" /></td>
    <td><input value="<?php echo($_POST['k5d2']); ?>"  type="text" name="k5d2" /></td>
    <td><input value="<?php echo($_POST['k5d3']); ?>"  type="text" name="k5d3" /></td>
    <td><input value="<?php echo($_POST['k5d4']); ?>"  type="text" name="k5d4" /></td>
    <td><input value="<?php echo($_POST['k5d5']); ?>"  type="text" name="k5d5" /></td>
    <td><input value="<?php echo($_POST['k5d6']); ?>"  type="text" name="k5d6" /></td>
    <td><input value="<?php echo($_POST['k5d7']); ?>"  type="text" name="k5d7" /></td>
    <td><input value="<?php echo($_POST['k5d8']); ?>"  type="text" name="k5d8" /></td>
    <td><input value="<?php echo($_POST['k5d9']); ?>"  type="text" name="k5d9" /></td>
    <td><input value="<?php echo($_POST['k5d10']); ?>"  type="text" name="k5d10" /></td>
    
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k6']); ?>"  type="text" name="k6" id="k6"/></td>
     
    <td><input value="<?php echo($_POST['k6d1']); ?>"  type="text" name="k6d1" /></td>
    <td><input value="<?php echo($_POST['k6d2']); ?>"  type="text" name="k6d2" /></td>
    <td><input value="<?php echo($_POST['k6d3']); ?>"  type="text" name="k6d3" /></td>
    <td><input value="<?php echo($_POST['k6d4']); ?>"  type="text" name="k6d4" /></td>
    <td><input value="<?php echo($_POST['k6d5']); ?>"  type="text" name="k6d5" /></td>
    <td><input value="<?php echo($_POST['k6d6']); ?>"  type="text" name="k6d6" /></td>
    <td><input value="<?php echo($_POST['k6d7']); ?>"  type="text" name="k6d7" /></td>
    <td><input value="<?php echo($_POST['k6d8']); ?>"  type="text" name="k6d8" /></td>
    <td><input value="<?php echo($_POST['k6d9']); ?>"  type="text" name="k6d9" /></td>
    <td><input value="<?php echo($_POST['k6d10']); ?>"  type="text" name="k6d10" /></td>
   
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k7']); ?>"  type="text" name="k7" id="k7"/></td>
    
    <td><input value="<?php echo($_POST['k7d1']); ?>"  type="text" name="k7d1" /></td>
    <td><input value="<?php echo($_POST['k7d2']); ?>"  type="text" name="k7d2" /></td>
    <td><input value="<?php echo($_POST['k7d3']); ?>"  type="text" name="k7d3" /></td>
    <td><input value="<?php echo($_POST['k7d4']); ?>"  type="text" name="k7d4" /></td>
    <td><input value="<?php echo($_POST['k7d5']); ?>"  type="text" name="k7d5" /></td>
    <td><input value="<?php echo($_POST['k7d6']); ?>"  type="text" name="k7d6" /></td>
    <td><input value="<?php echo($_POST['k7d7']); ?>"  type="text" name="k7d7" /></td>
    <td><input value="<?php echo($_POST['k7d8']); ?>"  type="text" name="k7d8" /></td>
    <td><input value="<?php echo($_POST['k7d9']); ?>"  type="text" name="k7d9" /></td>
    <td><input value="<?php echo($_POST['k7d10']); ?>"  type="text" name="k7d10" /></td>
    
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k8']); ?>"  type="text" name="k8" id="k8"/></td>
    
    <td><input value="<?php echo($_POST['k8d1']); ?>"  type="text" name="k8d1" /></td>
    <td><input value="<?php echo($_POST['k8d2']); ?>"  type="text" name="k8d2" /></td>
    <td><input value="<?php echo($_POST['k8d3']); ?>"  type="text" name="k8d3" /></td>
    <td><input value="<?php echo($_POST['k8d4']); ?>"  type="text" name="k8d4" /></td>
    <td><input value="<?php echo($_POST['k8d5']); ?>"  type="text" name="k8d5" /></td>
    <td><input value="<?php echo($_POST['k8d6']); ?>"  type="text" name="k8d6" /></td>
    <td><input value="<?php echo($_POST['k8d7']); ?>"  type="text" name="k8d7" /></td>
    <td><input value="<?php echo($_POST['k8d8']); ?>"  type="text" name="k8d8" /></td>
    <td><input value="<?php echo($_POST['k8d9']); ?>"  type="text" name="k8d9" /></td>
    <td><input value="<?php echo($_POST['k8d10']); ?>"  type="text" name="k8d10" /></td>
    
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k9']); ?>"  type="text" name="k9" id="k9"/></td>
     
    <td><input value="<?php echo($_POST['k9d1']); ?>"  type="text" name="k9d1" /></td>
    <td><input value="<?php echo($_POST['k9d2']); ?>"  type="text" name="k9d2" /></td>
    <td><input value="<?php echo($_POST['k9d3']); ?>"  type="text" name="k9d3" /></td>
    <td><input value="<?php echo($_POST['k9d4']); ?>"  type="text" name="k9d4" /></td>
    <td><input value="<?php echo($_POST['k9d5']); ?>"  type="text" name="k9d5" /></td>
    <td><input value="<?php echo($_POST['k9d6']); ?>"  type="text" name="k9d6" /></td>
    <td><input value="<?php echo($_POST['k9d7']); ?>"  type="text" name="k9d7" /></td>
    <td><input value="<?php echo($_POST['k9d8']); ?>"  type="text" name="k9d8" /></td>
    <td><input value="<?php echo($_POST['k9d9']); ?>"  type="text" name="k9d9" /></td>
    <td><input value="<?php echo($_POST['k9d10']); ?>"  type="text" name="k9d10" /></td>
   
  </tr>
  <tr>
    <td><input value="<?php echo($_POST['k10']); ?>"  type="text" name="k10" id="k10"/></td>
    
    <td><input value="<?php echo($_POST['k10d1']); ?>"  type="text" name="k10d1" /></td>
    <td><input value="<?php echo($_POST['k10d2']); ?>"  type="text" name="k10d2" /></td>
    <td><input value="<?php echo($_POST['k10d3']); ?>"  type="text" name="k10d3" /></td>
    <td><input value="<?php echo($_POST['k10d4']); ?>"  type="text" name="k10d4" /></td>
    <td><input value="<?php echo($_POST['k10d5']); ?>"  type="text" name="k10d5" /></td>
    <td><input value="<?php echo($_POST['k10d6']); ?>"  type="text" name="k10d6" /></td>
    <td><input value="<?php echo($_POST['k10d7']); ?>"  type="text" name="k10d7" /></td>
    <td><input value="<?php echo($_POST['k10d8']); ?>"  type="text" name="k10d8" /></td>
    <td><input value="<?php echo($_POST['k10d9']); ?>"  type="text" name="k10d9" /></td>
    <td><input value="<?php echo($_POST['k10d10']); ?>"  type="text" name="k10d10" /></td>
    
  </tr>
  
</table>

Open in new window

table.jpg
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
@RQ: Great idea.

I tried the seven49 link.  Here is my input URL:
http://www.nationalpres.org/

The output is attached here.

Best regards, ~Ray
nationalpres.org.pdf
Hmm. Overall, not bad. Graphics could be better rendered. It looks like it is quite low res (maybe the paid for service offers a greater quality).
Yes, it got the positioning right.  The JPG-boogers are not so great, but if I used PNG images, that might make the image rendering better.  On this particular site, there are a lot of low-resolution JPG images - artifacts of the day when most of our clients came via slow dial-up lines.
Avatar of eunoiabella
eunoiabella

ASKER

Hi Ray and RQuading,
Thanks for your suggestions. The seven49 link is good in theory, however, the problem I have with the is the url I have is one generic one that pulls out entries from my database as I enter...  so how can I differentiate individual records to then convert to pdf?
The first picture below shows the process of entry into the database, the code following shows how I am currently calling it, and the second picture shows the pdf table. As you can see it's not quite working properly. The right column of the input table is all the entries that are showing in the pdf and they are on the diagonal instead of a straight line column on the right... Any ideas? How do I get all the inputs show in their right place in the pdf?


case "keywordstable":
                                    $cellwidth = ((PAGEWIDTH - (PAGEMARGIN * 2)) * PDF_SCALING) / 12;
                                    $pdf->Cell($cellwidth * 2, FONTHEIGHT, "Competitors", 0, 0, "L");
                                    for ($i=0; $i<count($values["competitornames"]); $i++)
                                          $pdf->Cell($cellwidth, FONTHEIGHT, $values["competitornames"][$i], 0, 0, "L");

                                    $pdf->ln(FONTHEIGHT);
                                    $pdf->ln(FONTHEIGHT);

                                    foreach ($values["keywords"] as $key => $keyword)
                                    {
                                          $pdf->Cell($cellwidth * 2, FONTHEIGHT, $keyword, 0, 0, "L");
                                          for ($j=0; $j<count($values["competitors"][$key]); $j++)
                                                $pdf->Cell($cellwidth, FONTHEIGHT, $values["competitors"][$key][$i], 0, 0, "C");
                                    }
                                    break;
                              default:
                                    break;
tableforee2.jpg
tablesforee1.jpg
Anyone able to help me?.... the url to pdf suggestion wasn't useful because my url stays the same for multiple database records and I need to pull specific tables out of the database....
I'd really love it if someone could help me....
Thanks.
Well, as I said at the top, "This is a fairly substantial application development project" and EE is not well suited to doing application development - we are more of a forum where one can ask and answer questions - designing, writing and debugging program code is often beyond our ability - for that sort of thing a paid developer is what you need.

I recommended FPDF because it has worked for me when I needed to produce PDF files and I had the data available to me in a PHP script.  Richard recommended direct HTML-to-PDF classes as an easier alternative.  But either approach will require considerable time to integrate and debug.  I think we have answered the question and shown you some suitable tools, but we are not really in a position to do the debugging.

Best of luck with it, ~Ray
Split with Richard.  That's my $0.02, ~Ray