Hi all
I write index.php and pdf.php to list the documents (index.php) that i want my users to download in pdf format (pdf.php. I am using fpdf to generate the pdf and i got a working fine example.
The codes below generate the following error to me:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /path/to/downloads/pdf.php on line 17
Warning: Cannot modify header information - headers already sent by (output started at /path/to/downloads/pdf.php:17) in /path/to/fpdf/fpdf.php on line 998
FPDF error: Some data has already been output to browser, can't send PDF file
line 17 in psf.php is:
while($resultado = mysql_fetch_row($busca))
pdf.php:
//the only change i do here is to add the $id=$_GET[id] ,line
//and add the WHERE id=$id in the SQL statment
<?php
$id=$_GET[id];
define('FPDF_FONTPATH','/path/to/fpdf/font/');
require('../../fpdf/fpdf.php');
include("../cms/db.php");
$busca = mysql_query("SELECT * FROM table WHERE id=$id");
$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();
$pdf->SetFont('Arial', 'B', 10);
while($resultado = mysql_fetch_array($busca))
{
$pdf->ln();
$pdf->Cell(40,5,$resultado[titulo]);
$pdf->SetX(20);
$pdf->ln();
$pdf->SetFont('Arial', '', 10);
$pdf->Cell(60,5,$resultado[resumo])."\n";
$pdf->SetX(20);
$pdf->ln();
$pdf->MultiCell(180,5,$resultado[texto])."\n";
$pdf->SetX(20);
$pdf->ln();
$pdf->Cell(5,5,$resultado[dia]);
$pdf->Cell(5,5,$resultado[mes]);
$pdf->Cell(5,5,$resultado[ano]);
}
$pdf->Output();
?>
index.php
<?php
//include 'db.php';
$db = mysql_connect("host", "user", "pass");
mysql_select_db('db');
$query = "SELECT * FROM table";
$result = mysql_query($query, $db);
if (!$result) {printf ("ERROR"); exit;}
$numrows = mysql_num_rows($result);
$row=0;
print ("<table border=0 width=\"100%\">");
do
{
$myrow = mysql_fetch_row ($result);
if( ($row%2)==1) {
$bgcolor="#FFFF66";
}
else {
$bgcolor="#FFFF00";
}
print("<tr><td><b>$myrow[1]</b></td></tr>");
echo "<tr><td><a href=\"pdf.php?titulo=". $titulo . "&id=" . $myrow[0] . "\"> Read more ... >></a></td>\n</tr>";
//$row++;
}
while ($row < $numrows);
print ("</table>");
mysql_close($db);
?>
Thank´s in adcance for the solution !!!
Cheers
Angelo
http://amr.freezope.org