我正在构建一个允许用户查询表/数据库的表单。用户通过 HTML 下拉菜单从目录中选择要加载的表。这个下拉菜单由一个 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());
}