我不确定我做错了什么但是从下面的代码我可以下载一个pdf文件,但没有内容。它只显示列标题。有人请指出我做错了什么,谢谢。
//Connect to your database
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "test";
// Create con
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Select the what you want to show in your PDF file
$result = mysqli_query($conn, "SELECT id, name, amount, trans_id, msisdn, time_paid, status FROM customer");
//$number_of_products = $result->num_rows;
//Initialize the columns and the total
$column_id = "";
$column_name = "";
$column_amount = "";
$column_trans_id = "";
$column_msisdn = "";
$column_time_paid = "";
$column_status = "";
$total = 0;
//For each row, add the field to the corresponding column
while($row = mysqli_fetch_array($result))
{
$id = $row["id"];
$name = $row["name"];
$real_amount = $row["amount"];
$trans_id = $row["trans_id"];
$msisdn = $row["msisdn"];
$time_paid = $row["time_paid"];
$status = $row["status"];
$column_id = $column_id.$id."\n";
$column_name = $column_name.$name."\n";
$column_amount = $column_amount.$real_amount."\n";
$column_trans_id = $column_trans_id.$trans_id."\n";
$column_msisdn = $column_msisdn.$msisdn."\n";
$column_time_paid = $column_time_paid.$time_paid."\n";
$column_status = $column_status.$status."\n";
//Sum all the Prices (TOTAL)
$total = $total+$real_amount;
}
//mysql_close();
//Convert the Total Price to a number with (.) for thousands, and (,) for decimals.
//$total = number_format($total,',','.','.');
//Create a new PDF file
$pdf=new FPDF();
$pdf->AddPage();
//Fields Name position
$Y_Fields_Name_position = 20;
//Table position, under Fields Name
$Y_Table_Position = 26;
//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(232,232,232);
//Bold Font for Field Name
$pdf->SetFont('Arial','B',12);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(45);
$pdf->Cell(50,6,'Name',1,0,'L',1);
$pdf->SetX(65);
$pdf->Cell(100,6,'Amount',1,0,'L',1);
$pdf->SetX(85);
$pdf->Cell(200,6,'Mobile Number',1,0,'L',1);
$pdf->SetX(105);
$pdf->Cell(200,6,'Transation ID',1,0,'L',1);
$pdf->SetX(105);
$pdf->Cell(200,6,'Time Paid',1,0,'L',1);
$pdf->SetX(165);
$pdf->Cell(300,6,'Status',1,0,'R',1);
$pdf->Ln();
//Now show the columns
$pdf->SetFont('Arial','',12);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(45);
//$pdf->MultiCell(20,6,$column_name,1);
//$pdf->SetY($Y_Table_Position);
//$pdf->SetX(85);
$pdf->MultiCell(100,6,$column_amount,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(100,6,$column_msisdn,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(105);
$pdf->MultiCell(100,6,$column_time_paid,1);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(135);
$pdf->MultiCell(30,6,$column_status,1,'R');
$pdf->SetX(135);
$pdf->MultiCell(30,6,'$ '.$total,1,'R');
//Create lines (boxes) for each ROW (Product)
//If you don't use the following code, you don't create the lines separating each row
$i = 0;
$pdf->SetY($Y_Table_Position);
while ($i < $number_of_products)
{
$pdf->SetX(45);
$pdf->MultiCell(120,6,'',1);
$i = $i +1;
}
$pdf->Output();
?>