i have to print out a pdf report. the information in the pdf file coming from the database..how could i do it using php n mysql? i don't know...
is there anyone who can help me??
![]()
![]()
i have to print out a pdf report. the information in the pdf file coming from the database..how could i do it using php n mysql? i don't know...
is there anyone who can help me??
![]()
![]()
Hope you are talking about displaying a PDF report using PHP/MySQL combination.posted by syazyan
i have to print out a pdf report
You can find my code below for that purpose
The above code will retrieve some information, the info you want to furnish in the PDF file, from the database and put into the pdf and you can view the pdf file.PHP Code:<?php
//PDF file creation
$p = PDF_new();
/* open new PDF file; insert a file name to create the PDF on disk */
if (PDF_begin_document($p, "", "") == 0) {
die("Error: " . PDF_get_errmsg($p));
}
PDF_set_info($p, "Creator", "pdf.php");
PDF_set_info($p, "Author", "codeexploiter");
PDF_set_info($p, "Title", "Report");
PDF_begin_page_ext($p, 595, 842, "");
$font = PDF_load_font($p, "Helvetica-Bold", "winansi", "");
PDF_setfont($p, $font, 10.0);
PDF_set_text_pos($p, 1, 810);
PDF_show($p, "Company Report");
PDF_continue_text($p,"");
//Retrieving the information from the database
$user = "root";
$password = "";
$dbhost = "localhost";
$dbname = "PDF";
$link = mysql_connect($dbhost, $user, $passwd);
if(!link)
{
error_log(mysql_error(), "tmp/phplog.err");
}
else
{
$db = mysql_select_db($dbname, $link);
if(!db)
{
error_log(mysql_error(), "tmp/phplog.err");
}
else
{
$query = "SELECT matter from PDF";
$result = mysql_query($query,$link);
while($record = mysql_fetch_row($result))
{
PDF_continue_text($p, $record[0]);
}
PDF_end_page_ext($p, "");
PDF_end_document($p, "");
$buf = PDF_get_buffer($p);
$len = strlen($buf);
header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;
PDF_delete($p);
}
}
?>
Hope this will help you
i've read the code...but i don't understand where should i put these code..in a new php page?..how could i know whether the file retrieve the data from db or not..besides the select statement??..Originally Posted by codeexploiter
can u explain more detail??..i'm very new in creating pdf report using php...
You seem to be new to PHP in general. I suggest you take the time to get your head around the basics before trying something a little more complex like generating a PDF.If you just want to plow ahead anyway...a couple questions. What does the database look like? what exactly do you expect to happen?
Originally Posted by blm126
yes..i'm very new in php...i'm not just trying to generate the pdf..now i'm working and i need to generate the pdf...b4 this i've used the php but...not generating the pdf file...that's y i'm asking a detailed explaination..so i can study about it...![]()
i have a table called "comments" ...what i want to do is...when user click button report...a pdf report containing data from table "comments" will be generated and can be viewed by the user...![]()
You should have a database in which at least a table with some information on it.
Quoted by: codeexploiter
//Retrieving the information from the database
$user = "root";
$password = "";
$dbhost = "localhost";
$dbname = "PDF";you must specify the database user account through which you want to access the table. In my case i've used account root.Quoted by: codeexploiter
$user = "root";
Here you must specify the password for the user account rootQuoted by: codeexploiter
$password = "";
If you are testing this application in a single machine/your machine you can keep it like that or you can replace the localhost with the machine name on which your web server runs.Quoted by: codeexploiter
$dbhost = "localhost";
This is the database name in which i've my table from which i am gathering the information for generating a PDF report. You can replace the name with your own database name.Quoted by: codeexploiter
$dbname = "PDF";
This is based on my table and the field in it. I have a table named PDF in which i have a field matter which contains the data that I want to put into a PDF file.Quoted by: codeexploiter
$query = "SELECT matter from PDF";
You can replace this with your table name and field name.
Once you make the necessary changes in the code I provided in a way that it is compatible with your settings you can put this into a .PHP page and into the document root of your web server or any folder which is accessible from the document root.
The assumption here is that the database resides in the same machine of the web server.
You can mention the action attribute of a form where you have a button so whenever the user clicks that button it will execute the PHP code that I had provided.Quoted by: syazyan
i have a table called "comments" ...what i want to do is...when user click button report...a pdf report containing data from table "comments" will be generated and can be viewed by the user...
If you know how to invoke a php page using a front-end interface file then this wont' be much difficult for you to implement
"if(!db)"
Shouldn't that be "if(!$db)"?
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Yes it should be sorry for the typing mistake. Thanks for pointing it outposted by: djr33
"if(!db)"
Shouldn't that be "if(!$db)"?
i've copy the code n change it according to my db and table..but when user click report button..the following error occur...
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE = ''' at line 1"
this is my select statement..
$query = "SELECT * FROM comments WHERE rec_date = '$rec_date'";
$result = mysql_query($query,$link);
what does it means??...the code error at "where" statement?
i've done a pdf file...n i've succeed..but the problem is..i just could read n display the first row of data only...how can i view all the row of data based on specific date??
this is sample of my code...
<?php
//include ("../connectdb.pdf");
include ('class.ezpdf.php');
$db = @mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('e-account2', $db);
$query2 = "SELECT * FROM comments WHERE rec_date = '$rec_date'";
$result2 = mysql_query($query2,$db)or die(mysql_error());
$query_data2 = mysql_fetch_array($result2);
$no = $query_data2["no"];
$usr_cc = $query_data2["usr_cc"];
$rec_date = $query_data2["rec_date"];
$rec_time = $query_data2["rec_time"];
$call_name = $query_data2["call_name"];
$call_no = $query_data2["call_no"];
$company = $query_data2["company"];
$issue = $query_data2["company"];
$comments = $query_data2["comments"];
$pdf =& new Cezpdf();
$pdf->setEncryption('','rc',array('print'));
$i=$pdf->ezStartPageNumbers(500,720,9,'','',1);
$uppertext1 = "Record based on Date Call Received";
$pdf->selectFont('./fonts/Verdana.afm');
$pdf->setColor(0,0,0);
$pdf->addText(30,800,9,$uppertext1);
$data = array(
array('No'=>$no, 'Agent'=>$usr_cc, 'rec_time'=>$rec_time,'call_name'=>$call_name,'call_no'=>$call_no,
'company'=>$company, 'issue'=>$issue, 'comments'=>$comments));
}
could anybody help me??
Bookmarks