2011-06-08 102 views
0

我的代码正在生成PDF文档文件,但PDF中的输出仅作为变量打印,而不是数据库中的值。有人可以看看有什么问题吗?使用PHP从MYSQL数据库导出为PDF文档时出错

require('fpdf.php'); 

    mysql_connect("localhost","user","pwd") or die("Couldn't connect!"); 
    mysql_select_db("db_name") or die("Couldn't find db"); 

$pdf=new FPDF(); 
$pdf->AddPage(); 

$data = mysql_query("SELECT * FROM sold WHERE imei = '87712839712893'"); 

while ($result = mysql_fetch_assoc($data)) 
{ 
    $pdf->SetFont('arial','B',10); 
    $pdf->Cell(40,40,'$result["saledate"]'); 
    $pdf->SetFont('arial','B',30); 
    $pdf->Cell(40,10,'$result["sellingprice"]'); 
} 

// I don't know if the pdf Cell() command numeric arguments need to change or not. If they do, change them. 

$pdf->Output(); 

回答

0

您正在使用单引号:

$pdf->Cell(40,40,'$result["saledate"]'); 

导致无法得到解析的变量。

改为使用双引号。

+2

或不要在$ result [“saledate”] – 2011-06-08 18:53:13

+0

附近任何引号感谢您的帮助,但如果我只是删除单引号的结果是所需的。无论如何感谢您的帮助 – darsh 2011-06-08 18:56:24