| 6:45 pm on Sep 28, 2012 (gmt 0)|
I've been looking at the problem further, it appears that the issue is something to do with the $pdf section and actually writing to the document.
| 6:46 pm on Sep 28, 2012 (gmt 0)|
I'm sorry, I typed out my command incorrectly, I meant to say that this doesn't work:
| 7:12 pm on Sep 28, 2012 (gmt 0)|
$result['firstname'] is not a valid way to get to the firstname field. Should be $rows['firstname'] given the code you have.
I have FPDF implemented on one of my sites. If you continue to have problems I can probably help. But, it appears that you're just getting to your data incorrectly.
| 7:14 pm on Sep 28, 2012 (gmt 0)|
Was that a mis-type?
If you're looping through your results it should be $rows['firstname'];
But in your first example you are writing $rows['firstname'] into the $firstname variable - using the $firstname var isn't working? What is the output of $rows['firstname'] on a blank canvas?
| 7:21 pm on Sep 28, 2012 (gmt 0)|
Yes, I meant to say that I was putting
$pdf->Write(5,$result['firstname']); and not
I've amended the code as follows:
require_once("connections/connection.php"); // Connection to the server
require_once('fpdf/fpdf.php'); //FPDF classes
$tbl_name="sample_requests"; // Table name
$query = "SELECT * FROM $tbl_name WHERE request = 2 ";
$result = mysql_query($query) or die('Error, query failed');
while($rows = mysql_fetch_array($result));
However, I simply get a PDF generated onto a blank canvas.
| 7:29 pm on Sep 28, 2012 (gmt 0)|
Your exact PDF code works fine on my server if I put "test" in place of $rows['firstname'] . So either $rows['firstname'] is empty or your FPDF is somehow failing.
| 7:32 pm on Sep 28, 2012 (gmt 0)|
Is the text not being written to the PDF either? So just a white pdf file?
When I use this, I generally grab a pdf template, write on top of it, store it locally then grab and email it, for example.
A simple example of my use (not sure if your use would be similar, but using a template might be a good option - depending)
// initiate FPDI
$pdf = new FPDI();
// add a page
// set the sourcefile
$pdf->setSourceFile($base . '/email/form.pdf');
// import page 1
$template = $pdf->importPage(1);
// use the imported page and place it at point
$pdf->useTemplate($template, -5, 0, 220, 300);
$pdf_file= $base . '/email/results/'.time().'.pdf';
| 7:35 pm on Sep 28, 2012 (gmt 0)|
I've found that if I replace $rows['firstname'] with 'Test' I also get a PDF with the words firstname at the top but nothing when I try and pass something out of my database. I think its got to be something to do with the syntax that I'm using but I was sure that $pdf->Write(); was correct.
| 7:40 pm on Sep 28, 2012 (gmt 0)|
Possible the fact that you're looping outside of the PDF code is causing some unexpected results.
| 7:43 pm on Sep 28, 2012 (gmt 0)|
Hummm... how do you think would be the best way to put it then?
| 7:47 pm on Sep 28, 2012 (gmt 0)|
You're outputting the file for each db record, is that what you want? Does this even work? Wouldn't expect this to work, but if it does, and that's what you're trying to do then, OK. I don't know what you're trying to do, as obviously outputting a PDF with just a first name is not your objective.
| 7:54 pm on Sep 28, 2012 (gmt 0)|
Basically, I've written a PHP that displays all of the pending sample_requests at a company. Within the information that is requested is the name and address of the person who we'll be sending the sample too. I'm looking to export the name and address from the database and produce a PDF that I can then print as a shipping label. I thought I'd start by getting the person's first name printing on the PDF and then build things up from there.
| 7:59 pm on Sep 28, 2012 (gmt 0)|
I've never had to output a PDF before and I thought I was working along the right lines but I'm starting to think that I'm miles off!
| 2:39 am on Sep 29, 2012 (gmt 0)|
|I'm looking to export the name and address from the database and produce a PDF that I can then print as a shipping label. |
Ah. I wondered about that at the beginning of the thread. If you're sending it to someone else then I see why it has to be a PDF-- but if you're printing it yourself, does format matter? That is, don't spend time tearing out your hair if you can just use the same data to generate an appropriately formatted html page-- which I assume you can do standing on your head-- and print that instead.
| 9:38 pm on Sep 29, 2012 (gmt 0)|
|Thought I was working along the right lines but I'm starting to think that I'm miles off! |
You're doing it fine. You just need to make a PDF test page first, don't worry about the database. THEN add the database connectivity.
If you send me your email I can send you my FPDF code for creating an invoice so that you can check it out. I use the Cell command instead of Write so that I can control the text better. But it might be useful to see the code.
| 8:34 am on Sep 30, 2012 (gmt 0)|
Thank you wesmaster, I can print something like "Hello World" to a PDF but the database bit appears to be the difficult bit.
I've sent you a message with my email address on it :-)