用php搜索表单

时间:2012-02-10 23:58:19

标签: php mysql

我得到以下表格我的数据库包含2011年第1周到第20周和2012年第1周。我希望我的用户先选择2011,然后打电话给周选择例如他们不选择例如,第10周和第2012年(尚未提供)。非常欢迎任何帮助。

<form name="myform" action="http://www.website.com/displaybook.php" method="get">
    <select size="1" name="d"> 
    <?
    $sql=mysql_query("SELECT DISTINCT (Week) FROM data ORDER BY Week ASC");
    while($row = mysql_fetch_array($sql))
    {

     echo "<option value='". $row['Week']."'>Week - ". $row['Week']."</option>";

        }

    ?>  
    </select>

    <select size="1" name="y"> 
    <?
    $sql=mysql_query("SELECT DISTINCT (Year) FROM data ORDER BY Year Desc");
    while($row = mysql_fetch_array($sql))
    {

     echo "<option value='". $row['Year']."'>Season - ". $row['Year']."</option>";

        }

    ?>  

    </select>
    <input type="submit" value="Get data">
    </form>

1 个答案:

答案 0 :(得分:0)

你需要在year之前选择day选择......它会自动调整GET字符串...然后,你创建一个小的javascript来启用第二个选择被选中,如下:

<script type="text/javascript">
function getWeek()
{
    if (document.getElementById('y').value != '')
    {
        document.getElementById('d').disabled = ''; // this will enable the select
    }
}
</script>

在你的HTML中:

<form name="myform" action="http://www.website.com/displaybook.php" method="get">
<select size="1" name="y" onchange="getWeek()"> 
<?
$sql=mysql_query("SELECT DISTINCT (Year) FROM data ORDER BY Year Desc");
while($row = mysql_fetch_array($sql))
{
    echo "<option value='". $row['Year']."'>Season - ". $row['Year']."</option>";
}

?>  
</select>
<select size="1" name="d" id="d" disabled="disabled"> 
<?
$sql=mysql_query("SELECT DISTINCT (Week) FROM data ORDER BY Week ASC");
while($row = mysql_fetch_array($sql))
{
    echo "<option value='". $row['Week']."'>Week - ". $row['Week']."</option>";
}
?>  
</select>
<input type="submit" value="Get data">
</form>

这样的事情应该会很棒!