0

我终于从我的数据库中填充了我的第一个下拉框,但现在第二个下拉框甚至没有出现,我认为我的 if 语句调用第二个函数有问题,但不确定是什么也不确定我的“WHERE”是否我的查询中的语句是正确的 这是我的代码

echo "<tr>";
echo "<td>Department</td>";
echo "<td><div id=\"deptdiv\"><select name=\"department\">";
echo "<option>Select Department</option>";
echo "</td>";
while($row=mysql_fetch_array($result))
{
echo '<option value="'.$row['abbrev'].'">'.$row['abbrev'].'</option>';
}

if($_GET[department] == "department" && isset($_GET[department])) {
drop_2($_GET[department]);
}
function drop_2($id)
{
$query = mysql_query("SELECT courseno, name FROM course WHERE department=$id");

echo "<tr>";
echo "<td>Course</td>";
echo "<td><div id \"coursediv\"><select name=\"course\">";
echo "<option>Select Course</option>";
echo "</td>";
while($r=mysql_fetch_array($query))
{
echo '<option value="'.$r['courseno'].'">'.$r['name'].'</option>';
}
}
?>
4

2 回答 2

0

我很惊讶第一个下拉菜单显示,因为您在<select>元素中有表格标签,并且从未关闭该标签。我认为这是主要问题。试试看:

echo "<td><div id=\"deptdiv\"><select name=\"department\">";
echo "<option>Select Department</option>";
while($row=mysql_fetch_array($result))
{
  echo '<option value="'.$row['abbrev'].'">'.$row['abbrev'].'</option>';
}
echo "</select></div></td>";

此外,您需要在 GET 变量周围加上引号,以便 PHP 不会认为它们是常量,$_GET['department']并在 drop_2 函数的末尾关闭 select 标记。同样在函数中将</td>标签移动到关闭选择后。

希望有帮助。

于 2012-04-13T05:58:14.800 回答
0

这是您更正的代码..

 echo "<tr>";
echo "<td>Department</td>";
echo "<td><div id=\"deptdiv\"><select name=\"department\">";
echo "<option>Select Department</option>";
while($row=mysql_fetch_array($result))
{
echo '<option value="'.$row['abbrev'].'">'.$row['abbrev'].'</option>';
}
echo "</div>";
echo "</td></tr>";
if($_GET['department'] == "department" && isset($_GET['department'])) {
drop_2($_GET['department']);
}
function drop_2($id)
{
$query = mysql_query("SELECT courseno, name FROM course WHERE department=$id");

echo "<tr>";
echo "<td>Course</td>";
echo "<td><div id \"coursediv\"><select name=\"course\">";
echo "<option>Select Course</option>";
while($r=mysql_fetch_array($query))
{
echo '<option value="'.$r['courseno'].'">'.$r['name'].'</option>';
}
echo "</div>";
echo "</td></tr>";
}
?>
于 2012-04-13T06:15:47.807 回答