TCPDF and mysql - varying the data extracted

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grahambucknall
Forum Newbie
Posts: 6
Joined: Thu Feb 24, 2011 8:05 am

TCPDF and mysql - varying the data extracted

Post by grahambucknall »

pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hi
I have a table (applicant) and I am looking at producing a pdf displaying various items of data from this table.

I have succeeded in getting the look I want but in my query I use a fixed applicantid (in this case an id of 4). What I want to be able to do is to have the id cary according to the url. In other words, when someone comes from one web page to this one and the url is of the format .../pdf_production.php?applicantid=42.

I'm not sure I've explained that very well but I hope someone can help - I think this is the last thing I need to sort out.

Many thanks in advance.

The code I have so far is:

Code: Select all

<?php require_once('../Connections/process.php'); ?>
<?php 
require_once('../tcpdf/config/lang/eng.php');
require_once('../tcpdf/tcpdf.php');
     
// get data from users table 

mysql_select_db($database_process, $process);
$result = mysql_query("SELECT * FROM applicant WHERE applicantid = '4'"); 

while($row = mysql_fetch_array($result)) 
  { 
    $appid = $row['applicantid']; 
    $idcode = $row['idcode']; 
    $type = $row['type']; 
    $company = $row['company']; 
    $email = $row['email']; 
  } 
   
// create new PDF document 
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);  

$pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); 

// set default monospaced font 
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED); 

//set margins 
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT); 

//set auto page breaks 
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM); 

//set image scale factor 
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);  

//set some language-dependent strings 
$pdf->setLanguageArray($l);  

// --------------------------------------------------------- 

// set font 
$pdf->SetFont('dejavusans', '', 10); 

// add a page 
$pdf->AddPage(); 
// create some HTML content 
$txt = <<<EOD
Below are the details I require

Company type: $type
Company Name: $company
Company email: $email

EOD;


// output the HTML content 
// $pdf->writeHTML($htmlcontent, true, 0, true, 0); 
$pdf->Write(0, $txt, '', 0, 'L', true, 0, false, false, 0);

// $pdf->writeHTML($inlinecss, true, 0, true, 0); 

// reset pointer to the last page 
// $pdf->lastPage(); 

//Close and output PDF document 
$pdf->Output('example_006.pdf', 'I'); 

//============================================================+ 
// END OF FILE                                                  
//============================================================+ 
?>

pickle | Please use [ syntax=php ], [ syntax=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: TCPDF and mysql - varying the data extracted

Post by pickle »

Modify your code slightly to import the value from $_GET:

Code: Select all

$applicant_id = mysql_real_escape_string($_GET['applicantid']);
$result = mysql_query("SELECT * FROM applicant WHERE applicantid = '$applicant_id'");
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
grahambucknall
Forum Newbie
Posts: 6
Joined: Thu Feb 24, 2011 8:05 am

Re: TCPDF and mysql - varying the data extracted

Post by grahambucknall »

That's great - thank you.

Also, if I want to save the pdf to a location rather than see it in the browser (for example to a folder called documents) how do I amend the Output line?

Once again, many thanks.

Graham
Post Reply