它不是报告数据库中的数据并在 excel 中显示它,而是在 excel 中显示屏幕上的内容.. 我希望它显示 $excel 变量中包含的内容.. 下面是我的代码
if(isset($_POST['excel_report'])){
$select_query = "SELECT * FROM question_data";
$result = mysql_query($select_query);
$excel ='';
$excel .= "<table border ='0'>";
$excel .= "<tr> <td> Question Title </td> <td> Question Answer </td> </tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$excel .="<tr> <td>".$row['question_title']."</td> <td>".$row['question_response']."</tr>";
}
$excel .="</table>";
$filename ="questiondata.xls";
header('Content-type: application/ms-excel');
header('Content-Disposition: attachment; filename='.$filename);
echo $excel;
}
我的 HTML 表单,对于表单,元素是用 jquery 动态添加的。虽然我没有使用任何表单数据,我只是使用 excel 的提交按钮从数据库中获取数据并将其显示在电子表格..我哪里出错了?
<form action="/cms/form_test.php" method="post">
<h1> Test Form </h1>
<div class="test">
<input type ="hidden" name ="form_id" value ="4" />
<div id ="select_data">
<select id="select"> </select> <br /><br />
</div>
<div id ="options"></div>
<div id ="select_state">
<div id ="state_title"> </div>
<select id="select_state_dropdown"> </select> <br /><br />
</div>
</div>
<input type="submit" name ="excel_report" value="Export Question Data to Excel" />
<input type="submit" name ="submit" value="submit form" />
</form>