0
我正在構造一個允許用戶查詢表/數據庫的表單。用戶通過HTML下拉菜單選擇要從目錄加載的表格。該下拉菜單由一個PHP循環驅動,該循環讀取並顯示目錄中的文件(或表)。爲了實現對同一個表的多個查詢,用戶FIRST選擇一個複選框將他們查詢的表下載到同一目錄中,THEN SECOND從相同的下拉菜單中選擇他們的查詢文件。合理?提交表單後訪問使用PHP創建的文件
但是,在提交後,下拉菜單中新創建的文件不存在。該文件在頁面刷新後顯示。
現在的問題是:什麼是最好的方式來顯示新下載的表,以便在按下提交按鈕後立即通過下拉框(和PHP循環)識別它。我玩過javascript location.reload();但無濟於事。請參見下面簡化的代碼:
<html>
<form action = "" method = "post">
Table File: <select name="hfile">
<?php
$dir = "/Director/to/table/files";
$table_files = scandir($dir, 1);
//This is going to create the drop-down menu displaying all files in directory $dir.
$i = 0;
while($i <= count($table_files)) {
echo "<option value = $table_files[$i]> $table_file[$i] </option>";
$i = $i + 1;
}
?>
</select>
<!-- Below are just two of the form elements -->
<input type ="checkbox" name="download_table" value="download"> Download Queried Table
<input type = "submit" value="Submit" name="submit_query">
//Variables are set once the submit button is pressed
if(isset($_POST["submit_query"]))
{
$download_table = $_POST['download_table'];
}
//Download the table (if the download checkbox is on)
if(isset($download_table)) {
$file = "query.txt";
mysql_query("SELECT * FROM table INTO OUTFILE \"$file\" FIELDS TERMINATED BY ','") or die(mysql_error());
}
在哪裏聲明'$ download_table'?可能你正在談論'$ _POST ['download_table']'?而且,在刪除它之前,你應該檢查'/ Applications/MAMP/db/mysql/IESE/query.txt'是否存在(爲了避免消息)。 – MatRt 2013-03-12 02:56:00
對不起,一旦按下提交按鈕,我就聲明$ download_table(參見上面更正的代碼)。我也刪除了'unlink(「/ Applications /..../」')這一行,因爲這只是一種讓我在創建該應用程序時能夠將該目錄中的文件數量控制得小而且易於管理的方式。 ! – 2013-03-12 03:02:27
你在哪裏聲明'$ hypo_files'你的代碼有點混淆 – MatRt 2013-03-12 03:07:28