我需要一个脚本,从mysql加载数据并显示在下拉列表中。从那里,我需要将选定的数据传递到另一个页面。 我已经完成了第一步。我现在能够从mysql表加载数据并在下拉菜单中显示它们。具体如下所示。
<?php
include("config.php");
$result= mysql_query("SELECT folder_name FROM folders");
echo '<select name="directory">'; // Open your drop down box
while ($row = mysql_fetch_array($result)) {
//echo "<option>" . $row['folder_name'] . "</option>";
echo '<option value="'.$row['folder_name'].'">'.$row['folder_name'].'</option>';
}
echo '</select>';// Close your drop down box
?>
现在我需要帮助才能将所选数据传递到另一个页面。有什么建议吗?
答案 0 :(得分:1)
让我考虑form
从page2.php
张贴到page1.php
<强> page1.php中强>
<form method="post" action="page2.php">
//your dropdown code here
<?php
include("config.php");
$result= mysql_query("SELECT folder_name FROM folders");
$str = '';
$str .= '<select name="directory">'; // Open your drop down box
while ($row = mysql_fetch_array($result)) {
$str .= '<option value="'.$row['folder_name'].'">'.$row['folder_name'].'</option>';
}
$str .= '</select>';// Close your drop down box
echo $str;
?>
<input type="submit" value="submit" />
</form>
在page2.php中,您可以访问dropdown
所选值
$selVal = '';
if(isset($_POST['directory']))
{
$selVal = $_POST['directory'];
}
答案 1 :(得分:1)
创建一个javascript函数来处理带有文件夹名称数据的重定向:
function changePage(folder){
window.location.href= 'http://www.yourdomain.com/page2.php?folder=' + folder;
}
onchange选项,触发changePage javascript函数,文件夹名称为输入:
include("config.php");
$result= mysql_query("SELECT folder_name FROM folders");
echo '<select name="directory">'; // Open your drop down box
while ($row = mysql_fetch_array($result)) {
echo '<option value="'.$row['folder_name'].'" onchange="changePage(\''.$row['folder_name'].'\')">'.$row['folder_name'].'</option>';
}
echo '</select>';// Close your drop down box
page2.php
$folder_name = strip_tags($_GET['folder']);