将表从MySQL生成为PDF(使用PHP)
我正在尝试将表(已过滤)从MySQL导出到pdf 这里的主要问题是它只打印列表上的最后一个结果,而不是打印所有结果 我尝试过其他代码,但仍然得到相同的结果。我不知道我的代码有什么问题:将表从MySQL生成为PDF(使用PHP),php,mysql,pdf,fpdf,mpdf,Php,Mysql,Pdf,Fpdf,Mpdf,我正在尝试将表(已过滤)从MySQL导出到pdf 这里的主要问题是它只打印列表上的最后一个结果,而不是打印所有结果 我尝试过其他代码,但仍然得到相同的结果。我不知道我的代码有什么问题: <?php include("configsample.php"); ?> <?php $string=$_GET['string']; $course=$_GET['course']; $category=$_GET['category']; $from=$_GET['from']; $to
<?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;
?>
追加$html2。您正在循环中赋值,所以它只显示最后一条记录
像这样使用
$html2=$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>';
$html2=$html2'
“.$行['restu_title']。”
“.$行[“剩余年份]。”
“.$行['restu_by']。”
“.$行['restu_ad']
“.$row['restu_panel']”
';
追加$html2。您正在循环中赋值,所以它只显示最后一条记录
像这样使用
$html2=$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>';
$html2=$html2'
“.$行['restu_title']。”
“.$行[“剩余年份]。”
“.$行['restu_by']。”
“.$行['restu_ad']
“.$row['restu_panel']”
';
您需要修改文本字符串,以避免下一个值覆盖$html2
每次循环运行时,$html2
都会被新值覆盖。在本例中,您需要在等号前添加一个点:
while ($row = mysql_fetch_assoc($sql_result)){
$html .='<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>';
}
while($row=mysql\u fetch\u assoc($sql\u result)){
$html.='
“.$行['restu_title']。”
“.$行[“剩余年份]。”
“.$行['restu_by']。”
“.$行['restu_ad']
“.$row['restu_panel']”
';
}
小心正确放置
。如果SQL请求没有结果,表将不会关闭,从而导致HTML无效
您需要这样做:
$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)){
$html .='<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>';
}
}
$html .= '</table>';
$html='1!'
研究题目
年
倡议人
顾问
研究小组
';
$sql\u result=mysql\u query($sql,$connection)或die('request“无法执行sql查询“。$sql);
如果(mysql\u num\u行($sql\u结果)>0){
而($row=mysql\u fetch\u assoc($sql\u result)){
$html.='
“.$行['restu_title']。”
“.$行[“剩余年份]。”
“.$行['restu_by']。”
“.$行['restu_ad']
“.$row['restu_panel']”
';
}
}
$html.='';
您需要修改文本字符串,以避免下一个值覆盖$html2
每次循环运行时,$html2
都会被新值覆盖。在本例中,您需要在等号前添加一个点:
while ($row = mysql_fetch_assoc($sql_result)){
$html .='<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>';
}
while($row=mysql\u fetch\u assoc($sql\u result)){
$html.='
“.$行['restu_title']。”
“.$行[“剩余年份]。”
“.$行['restu_by']。”
“.$行['restu_ad']
“.$row['restu_panel']”
';
}
小心正确放置
。如果SQL请求没有结果,表将不会关闭,从而导致HTML无效
您需要这样做:
$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)){
$html .='<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>';
}
}
$html .= '</table>';
$html='1!'
研究题目
年
倡议人
顾问
研究小组
';
$sql\u result=mysql\u query($sql,$connection)或die('request“无法执行sql查询“。$sql);
如果(mysql\u num\u行($sql\u结果)>0){
而($row=mysql\u fetch\u assoc($sql\u result)){
$html.='
“.$行['restu_title']。”
“.$行[“剩余年份]。”
“.$行['restu_by']。”
“.$行['restu_ad']
“.$row['restu_panel']”
';
}
}
$html.='';
在whileloop中覆盖$html2。只要还有另一条记录,它就会被提取,html2将始终包含最后一条记录的值。您在whileloop中覆盖$html2。只要还有另一条记录,它就会被获取,html2将始终包含最后一条记录的值。谢谢你的建议。我尝试替换代码,但它给了我以下错误:“mPDF错误:某些数据已经输出到浏览器,无法发送PDF文件:当您有var_dump或$mPDF->之前的任何错误时,会出现此消息。尝试var_dump($html)没有制作pdf以查看是否没有关于de sql请求的错误。感谢您的建议。我尝试替换代码,但它给了我以下错误:“mPDF错误:某些数据已经输出到浏览器,无法发送pdf文件:当您有var_dump或$mPDF->之前的任何错误时,会出现此消息。尝试在不生成pdf的情况下使用var_dump($html)来查看是否没有关于de sql请求的错误。谢谢您的建议。我尝试替换代码,但出现以下错误:“mPDF错误:某些数据已输出到浏览器,无法发送PDF文件:感谢您的建议。我尝试替换代码,但出现以下错误:“mPDF错误:某些数据已输出到浏览器,无法发送PDF文件: