I have created a html form. In that I have 2 drop down lists. Drop-down list1 retrieves values from sql database table and displays over there. Now I want to display another drop-down list with input from drop-down list 1.
This is my code:
<label for="bname">Select a Building</label>
<?php
session_start();
include 'db_connection.php';
$conn = OpenCon();
$sql = "SELECT bname FROM building_details";
$result = mysqli_query($conn, $sql);
echo "<select name='bname'>";
while ($row = mysqli_fetch_array($result)){
echo "<option value='". $row['bname'] ."'>".$row['bname'] ."</option>";
}
echo "</select>";
echo "<label for='rtype'>Select a rtype</label>";
$sql2 = "SELECT rtype FROM room_details WHERE bname='bname'";
$result2 = mysqli_query($conn,$sql2);
echo "<select name='rtype'>";
while ($row2 = mysqli_fetch_array($result2)){
echo "<option value='". $row2['rtype'] ."'>".$row2['rtype'] ."</option>";
}
echo "</select>";
Here once bname value From building_details is selected then based on that input I need to display another dropdown list which is the rtype column from room_details table. Can some one help me with this???