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
eunoiabellaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Not sure I understand how best to answer this question, but I will try to provide some guidance.  This is a fairly substantial application development project.  Nothing is very "hard" - it is just a lot of code that needs to be written and tested.  The general logic flow would be like this:

1. Query the data base. Get the values for all the fields in the table (if any) from the data base.
2. Present the table in a form to receive client input.  The form fields are prepopulated with whatever you found in the data base.
3. Receive the form in $_POST, validate its contents, handle errors, update the data base with the new client input.
4. Use the validated fields that you have just put into the data base to create the FPDF object.

The look and feel of the table on the client screen is going to be controlled by HTML table, tr, td and styled by CSS.  The look and feel of the PDF file is going to be controlled by your positioning statements that you send to FPDF.  As far as I know there is no generalized way to turn HTML tables and CSS into a set of FPDF commands.

In using FPDF, I have found it useful to use variables or define() constants for all the color numbers and positioning elements.  Since colors are somewhat dependent on the printer, and since you can adjust positions to about 1/100 inch, being able to tinker with these fields is important to getting a good final output.

HTH, ~Ray
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Richard QuadlingSenior Software DeveloperCommented:
There are several HTML2PDF classes and services around.

Paid for service
http://html2pdf.seven49.net/Web/
http://forum.htm2pdf.co.uk/viewtopic.php?f=4&t=9

Classes
http://html2fpdf.sourceforge.net/
http://www.digitaljunkies.ca/dompdf/index.php

The more complexity the HTML has, the harder it is to convert.

This route is probably easier than manually creating the PDF to match the rendered output.
0
Ray PaseurCommented:
@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
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Richard QuadlingSenior Software DeveloperCommented:
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).
0
Ray PaseurCommented:
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.
0
eunoiabellaAuthor Commented:
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?
0
eunoiabellaAuthor Commented:
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
0
eunoiabellaAuthor Commented:
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.
0
Ray PaseurCommented:
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
0
Ray PaseurCommented:
Split with Richard.  That's my $0.02, ~Ray
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.