hi - i have coded a seacrch box and its results are displayed in a tabular form.
i have also a print button which when pressed shud create a pdf based on that table that is displayed. for this i have a separate page called pdf.php. i am using ezpdf for this.
instead of writing the query twice.. is there a way for the pdf to be created based on what query combination the search user selects? do we need sessions for this?
here is the pdf.php
<?php
session_start();
?>
<?php
# Catch the posted data, validate by getting rid of > and <
$header =$_POST['header'];
# Replace > and < with a blank space
$header = str_replace('<','',$header);
$header = str_replace('>','',$header);
$body =$_POST['body'];
# Replace > and < with a blank space
$body = str_replace('<','',$body);
$body = str_replace('>','',$body);
# Include the file that does all of the work
include ('class.ezpdf.php');
# Start a new PDF file
$pdf =& new Cezpdf();
# Select the font we'll be using. There are more fonts in the zip file.
$pdf->selectFont('./fonts/Helvetica.afm');
# include the header, then move down a couple of lines, font size 25
# justification centered (centred if you're from the UK)
$pdf->ezText($header . "\n\n",25,array('justification'=>'centre'));
# include the body after moving down 7 lines to get under the pic.
# Font size 16, justification centered.
$pdf->ezText("\n\n\n\n\n\n\n" . $body,16,array('justification'=>'centre'));
//inside
$pdf->ezText('Hello World!',20);
//--------------------------------------------------
// you will have to change these to your settings
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'sdc_cpds';
//$query = 'SELECT * FROM course_participant';
$query = $_GET["resultset"];
//--------------------------------------------------
/*
$data = array( array('Name'=>1,'Address'=>'gandalf','Contact Number'=>'wizard','Email'=>'wizard','Gender'=>'wizard','Age'=>'wizard','Marital Status'=>'wizard','University'=>'wizard','Fac/Dept'=>'wizard','Course'=>'wizard','Course Date'=>'wizard','Reg Date'=>'wizard') );
*/
//$pdf->ezTable($data);
// open the connection to the db server
$link = mysql_connect($host,$user,$password);
// change to the right database
mysql_select_db($database);
// initialize the array
$data = array();
// do the SQL query
$result = mysql_query($query);
// step through the result set, populating the array, note that this could also have been written:
// while($data[] = mysql_fetch_assoc($result)) {}
while($data[] = mysql_fetch_array($result, MYSQL_ASSOC)) {}
// make the table
$pdf->ezTable($data);
// do the output, this is my standard testing output code, adding ?d=1
// to the url puts the pdf code to the screen in raw form, good for checking
// for parse errors before you actually try to generate the pdf file.
if (isset($d) && $d){
$pdfcode = $pdf->output(1);
$pdfcode = str_replace("\n","\n<br>",htmlspecialchars($pdfcode));
echo '<html><body>';
echo trim($pdfcode);
echo '</body></html>';
} else {
$pdf->stream();
}
#create the pdf and stream it to the page
$pdf->output();
$pdf->ezStream();
?>