我的网站上有一个下拉菜单,里面有一个数据库表的值,显示了我学校的所有学校班级。现在我有了第二个页面,其中显示了数据库表中的所有学生,这些学生位于所选课程中,带有复选框。
我现在的问题如下: 如何将这两个页面合二为一?因此,当我只是在下拉菜单中选择课程而不按提交按钮时,所有选定班级的学生都会显示。
我的源代码: 1)选择班级的网站代码:
<html>
<?php
$db_host = "localhost";
$database = "internat_db";
$con=mysqli_connect($db_host, "root", "", $database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$klassen = mysqli_query($con, "Select * from klassen");
echo '<form action="schueler_ausgabe.php" method="POST">';
echo '<select name="Klassenwahl">';
while($row = mysqli_fetch_array($klassen))
{
echo "<option value=".$row['Klasse'].">".$row['Klasse']."</option>";
}
echo '<input id="submit" name="submit" type="submit" value="Auswaehlen" />';
echo '</form>';
mysqli_close($con);
?>
</html>
2)显示所有学生的网站代码:
<html>
<?php
$klassenname = $_POST["Klassenwahl"];
$db_host = "localhost";
$database = "internat_db";
$con=mysqli_connect($db_host, "root", "", $database);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
$zw = "Select vorname, nachname FROM schueler WHERE klasse = '".$klassenname."'";
$schueler = mysqli_query($con, $zw);
echo '<form action="" method="POST">';
while($row = mysqli_fetch_array($schueler))
{
echo "<input type='checkbox' name='schueler' value=".$row['vorname']." ".$row['nachname'].">".$row['vorname']." ".$row['nachname']."";
echo '<br>';
}
echo '<input id="submit" name="submit" type="submit" value="Auswaehlen" />';
echo '</form>';
mysqli_close($con);
?>
</html>
非常感谢您的任何帮助/想法!