我試圖導出表格(過濾)從MySQL到PDF。從MySQL生成表格到PDF(使用PHP)
這裏的主要問題是,它只打印列表中的最後一個結果,而不是打印所有結果。
我試過其他代碼,但我仍然得到相同的結果。我不知道我的代碼有什麼問題:
<?php
include("configsample.php");
?>
<?php
$string=$_GET['string'];
$course=$_GET['course'];
$category=$_GET['category'];
$from=$_GET['from'];
$to=$_GET['to'];
if ($_REQUEST["string"]<>'') {
$search_string = " AND restu_title LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%'";
}
if ($_REQUEST["course"]<>'') {
$search_course = " AND restu_course='".mysql_real_escape_string($_REQUEST["course"])."'";
}
if ($_REQUEST["category"]<>'') {
$search_category = " AND category='".mysql_real_escape_string($_REQUEST["category"])."'";
}
if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year BETWEEN '".mysql_real_escape_string($_REQUEST["from"])."' AND '".mysql_real_escape_string($_REQUEST["to"])."'".$search_string.$search_course;
} else if ($_REQUEST["from"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year = '".mysql_real_escape_string($_REQUEST["from"])."'".$search_string.$search_course;
} else if ($_REQUEST["to"]<>'') {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_year = '".mysql_real_escape_string($_REQUEST["to"])."'".$search_string.$search_course;
} else {
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE restu_id>0".$search_string.$search_course.$search_category;
}
$html='<table>
<tr style="color:#010101; font:bold 13px Times New Roman; height:40px;">
<th>Research Title</th>
<th>Year</th>
<th>Proponent(s)</th>
<th>Adviser</th>
<th>Research Panel</th>
</tr>';
$sql_result = mysql_query ($sql, $connection) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0) {
while ($row = mysql_fetch_assoc($sql_result)){
$html2='<tr>
<td style="padding:10px;">'.$row['restu_title'].'</td>
<td style="padding:10px;">'.$row['restu_year'].'</td>
<td style="padding:10px;">'.$row['restu_by'].'</td>
<td style="padding:10px;">'.$row['restu_ad'].'</td>
<td style="padding:10px;">'.$row['restu_panel'].'</td>
</tr>
</table>';
}
}
include("mpdf60/mpdf.php");
$mpdf=new mPDF('c','Letter','','',20,20,18,16,9,9,'L');
$mpdf->SetDisplayMode('fullpage');
$mpdf->AddPage('L');
$mpdf->WriteHTML($html);
$mpdf->WriteHTML($html2);
$mpdf->Output();
exit;
?>
你在你的while循環覆蓋$ HTML2。只要有另一條記錄,它將被提取,並且html2將始終包含最後一條記錄的值。 – Twinfriends