使用PHP从MYSQL数据库导出到PDF文档时出错


Error in exporting to PDF document using PHP from MYSQL database

我的代码正在生成pdf文档文件,但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();

您使用的是单引号:

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

导致变量无法解析。

请改用双引号。