I have made a big process since last question. I have almost finished my little challenge.
Now I have another problem: I have two drop down lists (select elements) items in html code. In the first one I can choose a (school) subject. If this value change, I want that the second drop down list will update its options, as an example:
First drop down: History Second drop down: World War, French Revolution
First drop down: Geography Second drop down: Capitals, Where is...
Here is my code:
<?php
session_start();
if(isset($_SESSION['schueler'])) {
if($_SESSION['schueler'] == 3) {
?>
<!DOCTYPE html>
<html>
<head>
<title>LA4S - Schülerbereich</title>
<link href="./Style/style.css" type="text/css" rel="stylesheet">
</head>
<body>
<script type="text/javascript">
function getquestions() {
document.getElementById("getquestions").style.visibility = "visible";
}
</script>
<div>
<img src="./Pictures/logo_small.png" width="100" id="logo" /> <span class="title">Schülerbereich</span>
</div>
<br />
<div class="menu">
<a onclick="getquestions()">Fragen beantworten</a>
<a style="text-decoration: none;" href="login.php?logout=3">Ausloggen</a>
</div>
<br />
<div id="getquestions">
<table>
<form action="home.php" method="post">
<tr>
<td>
Fach
</td>
<td>
<select name="subject" size="1" id="type_select">
<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbase = "la4s";
$db = mysqli_connect($host, $user, $pass, $dbase);
if (mysqli_connect_errno())
{
echo mysqli_connect_errno();
die ("Error");
}
$getSubjectsForForm = mysqli_query($db, "SELECT * FROM subject");
while($ResultArray = mysqli_fetch_array($getSubjectsForForm)) {
echo '<option value="'.$ResultArray['sid'].'">'.$ResultArray['subject'].'</option>';
}
mysqli_close($db);
?>
</select>
</td>
</tr>
<tr>
<td>
Thema
</td>
<td>
<select name="theme" size="1" id="type_select">
<?php
$host = "localhost";
$user = "root";
$pass = "";
$dbase = "la4s";
$db = mysqli_connect($host, $user, $pass, $dbase);
if (mysqli_connect_errno())
{
echo mysqli_connect_errno();
die ("Error");
}
$subject = $_POST['subject'];
$getThemesOfThatSubject = mysqli_query($db, "SELECT * FROM theme WHERE sid =".$subject.";");
while($ResultArray = mysqli_fetch_array($getThemesOfThatSubject)) {
echo '<option value="'.$ResultArray['tid'].'">'.$ResultArray['theme'].'</option>';
}
mysqli_close($db);
?>
</select>
</td>
</tr>
<tr>
<td colspan="2" id="button_login">
<input type="submit" name="submit" value="Fragen beantworten" />
</td>
</tr>
</form>
</table>
</div>
<?php
}
else {
echo "Zugriff verweigert!";
}
}
else {
echo "Zugriff verweigert!";
}
?>
</body>
</html>
The first drop down list is called subject and the second one is called theme.
So I try again to explain: If the value in drop down list subject changes, the drop down list theme will update its options.
I hope you can help me.
Greeez Tomi