Q:

I want to get dropdown values based on previous dropdown selection PHP

I have 2 dropdown options but I want them to be retrieved once the first dropdown value is selected or like the second dropdown options depend on the first dropdown option 
    <select name="campusselect">
            <?php 
                $result= $conn->query("select campus_name from campus");
                while( $row = $result->fetch_assoc()) {
                    $campus_name=$row['campus_name'];
                    echo "<option value='$campus_name'>$campus_name</option>"; 
                }                  
            ?>
        </select>

    <!--room drop down-->
        <select name="roomsselect">
            <?php 
                $result= $conn->query("SELECT room_name FROM rooms WHERE room_campus=".$campus_name);
                while( $row = $result->fetch_assoc()) {
                    $room_name=$row['room_name'];
                    echo "<option value='$room_name'>$room_name</option>"; 

                }
            ?>
        </select>

A:

Focussing on these two SELECT menus only and using just a small piece of Javascript you could try something like the following. The javascript event listener issues a GET request when there is a change event on the first dropdown. The querystring parameter campus is then used in the sql satement for the 2nd dropdown.
<select name="campusselect">
<?php 
    $result= $conn->query("select `campus_name` from `campus`");
    while( $row = $result->fetch_assoc() ) {
        printf( '<option>%s', $row['campus_name'] );
    }                  
?>
</select>

<script>
    document.querySelector('select[name="campusselect"]').addEventListener('change', function(e){
        location.search='campus='+this.value;
    });
</script>

<!--room drop down-->
<select name="roomsselect">
<?php
    if( isset( $_GET['campus'] ) ){
        $sql='select `room_name` from `rooms` where `room_campus`=?';
        $stmt=$conn->prepare($sql);
        $stmt->bind_param('s',$_GET['campus']);
        $res=$stmt->execute();
        $stmt->bind_result($room);

        while( $stmt->fetch() )printf('<option>%s',$room);
    }
?>
</select>

