My problem is very simple.
This is my code:
<?php
include "../../../koneksi.php";
?>
<html>
<body>
<form action="" method="POST">
<?php
if($_POST['menu'] === "lunchmenu"){
$result = mysqli_query($conn,"SELECT * FROM tb_lunch");
} else{
$result = mysqli_query($conn,"SELECT * FROM tb_dinner");
}
?>
<table>
<tr>
<td>Kategori Menu</td>
<td>
<select name="menu" onchange="this.form.submit();">
<option selected="true" disabled>-- Menu Category --</option>
<option value="lunchmenu">Lunch Menu </option>
<option value="dinnermenu">Dinner Menu </option>
</select>
</td>
</tr>
<tr>
<td>Menu Name</td>
<td>
<select>
<?php
if($_POST['menu'] === "lunchmenu")
$i = 1;
while ( $row = mysqli_fetch_assoc($result)):
?>
<option> <?=$row[menu_name]; ?></option>
<?php
$i++;
endwhile;
?>
<?php
if($_POST['menu'] === "dinnermenu")
$i = 1;
while ( $row = mysqli_fetch_assoc($result)):
?>
<option> <?=$row[menu_name]; ?></option>
<?php
$i++;
endwhile;
?>
</select>
</td>
</tr>
</table>
</form>
</body>
</html>
The results that I want is very simple. When I choose "Lunch Menu" from --Menu Category--, it will show me the available lunch menu. I got no problem in here. My problem is: After I choose a menu (lunch or dinner), the page will refresh and it will be back just like the default value of --Menu Category--, though it shows the correct menu below.
I think the problem is at onchange="this.form.submit();
Do you guys has any solution for this?