我正在使用php & mysql。使用php創建PDF文件?
我想檢索數據庫中的表中的所有記錄,並將它們打印到pdf文件中。
我寫了一些代碼,但它只檢索表中的第一條記錄,而沒有檢索到所有其他記錄。
這裏是我的代碼:
<?php
$con = mysql_connect("localhost","root","")
or die("Failed to connect to the server: " . mysql_error());
mysql_select_db("Users")
or die("Failed to connect to the database: " . mysql_error());
$query = mysql_query("SELECT * FROM reservations");
$numrows = mysql_num_rows($query);
if($numrows > 0)
{
while($result = mysql_fetch_assoc($query))
{
$db_id = $result['id'];
$db_fname = $result['fname'];
$db_lname = $result['lname'];
$db_email = $result['email'];
$db_phone = $result['phone'];
$db_day = $result['day'];
$db_time = $result['time'];
$db_cartype = $result['car_type'];
$db_carcolor = $result['car_color'];
$db_carmodel = $result['car_year'];
$db_carno = $result['car_no'];
$db_problem = $result['problem'];
$db_status = $result['status'];
$db_remtime = $result['remaining_time'];
$db_cost = $result['cost'];
$db_payment = $result['payment'];
$db_date = $result['date'];
require("FPDF/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont("Arial","B","15");
$pdf->Cell(0,10,"Freedom Car: Total Reservations",1,1,"C");
$pdf->Image("porchue.jpg");
$pdf->SetFont("Arial","","10");
$pdf->Write(5,"ID: $db_id\n");
$pdf->Write(5,"First Name: $db_fname\n");
$pdf->Write(5,"Last Name: $db_lname\n");
$pdf->Write(5,"Email Address: $db_email\n");
$pdf->Write(5,"Phone Number: $db_phone\n");
$pdf->Write(5,"Reserved Day: $db_day\n");
$pdf->Write(5,"Reserved Time: $db_time\n");
$pdf->Write(5,"Car Type: $db_cartype\n");
$pdf->Write(5,"Car Color: $db_carcolor\n");
$pdf->Write(5,"Car Model: $db_carmodel\n");
$pdf->Write(5,"Car Number: $db_carno\n");
$pdf->Write(5,"Car Problem: $db_problem\n");
$pdf->Write(5,"Car Status: $db_status\n");
$pdf->Write(5,"Remaining Time: $db_remtime\n");
$pdf->Write(5,"Total Cost: $db_cost\n");
$pdf->Write(5,"Payment Method: $db_payment\n");
$pdf->Write(5,"Reservation Date: $db_date\n\n");
$pdf->Output();
}
}
else
echo "<h4>Sorry, No reservations at this time.</h4>";
?>
看看什麼應該和不應該在那裏while循環 –
我不明白你,請解釋你的想法在代碼中不只是在一些文本。 @Dagon –