我的数据中有以下内容
Year Week
2011 19
2011 18
2011 17
2012 1
我创建了一个下拉列表表单以显示信息
<script type="text/javascript">
function getWeek()
{
if (document.getElementById('y').value != '')
{
document.getElementById('d').disabled = ''; // this will enable the select
}
}
</script>
<form name="myform" action="http://www.website.com/displaybook.php" method="get">
<select size="1" name="y" id ="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>
我的问题是,我希望它仅显示2012年选定的2012年和2011年选择2011年等的一周...
答案 0 :(得分:1)
尝试删除
while($row = mysql_fetch_array($sql))
{
echo "<option value='". $row['Year']."'>Season - ". $row['Year']."</option>";
}