0
<?php
mysql_connect('localhost','root','root');
mysql_select_db('project');
$dbname="project"
require('fpdf.php');

//Connect to your database
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");


//Create new pdf file
$pdf=new FPDF();

//Open file
$pdf->Open();

//Disable automatic page break

//Add first page
$pdf->AddPage();

//set initial y axis position per page
$y_axis_initial = 25;


$pdf->SetX(25);
$pdf->Cell(30, 6, 'id', 1, 0, 'L', 1);
$pdf->Cell(30, 6, 'Studentid', 1, 0, 'R', 1);

//Select the Products you want to show in your PDF file
$result=mysql_query('select * from add_marks');

//initialize counter
//Set maximum rows per page
//Set Row Height

while($row = mysql_fetch_array($result))
{
        //print column titles for the current page
        $pdf->SetY($y_axis_initial);
        $pdf->SetX(25);
        $pdf->Cell(30, 6, 'id', 1, 0, 'L', 1);

        $pdf->Cell(30, 6, 'Studentid', 1, 0, 'R', 1);

        //Go to next row
    $id = $row['id'];
    $Studentid = $row['Studentid'];
    //Go to next row
}

//Create file
$pdf->Output();
?>

<?php
$result = mysql_query("SHOW COLUMNS FROM add_marks");

 $i = 0;

if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result))
{

$csv_output .='"'.$row['id'].'","';

$i++;}
}
$csv_output .= "n";
$values = mysql_query("SELECT * FROM add_marks");

while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j].",";

}
$csv_output .= "n";
}
$filename = $file."_".date("d-m-Y_H-i",time());


header("Content-type: application/pdf");
header("Content-disposition: pdf" . date("Y-m-d") . ".pdf");
header( "Content-disposition: filename=".$viewresults1.php".pdf");

print $csv_output;

exit;
?>

**jst help me to convert database record to pdf file format and then display the pdf file on the form i hv tried the abv cord bt it does nt work db table is the same as i mentioned earlier pls give me the result as fst as possible *

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by ryantroop
0

k.. so first off, you are connecting to your database twice, for no reason

mysql_connect('localhost','root','root');mysql_select_db('project');$dbname="project"require('fpdf.php');//Connect to your databasemysql_connect("$host", "$username", "$password")or die("cannot connect");mysql_select_db("$db_name")or die("cannot select DB");

all that could be simplified...

$usr = 'usrname';
$pw = 'pw';
$host = 'localhost';
$dbname = "project";

$db = mysql_connect($host, $usr, $pw);
mysql_select_db($dbname, $db) or die ('Could not connect to MySQL: '.mysql_error());

Most of that should be in an include file, that is above your root.

Then, include_once('fpdf.php'); is fine...

You create your pdf file as per the fpdf object...

After that... Im having a little trouble following what your code is trying to accomplish...

you have

$filename = a non existent $file variable
and

you have a header that refers to a non existent variable $viewresults1.php... which... Im not even quite sure what to make of....

A little more info would be helpful in order to help you...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.