php两个依赖的下拉列表mysql查询获取到数组

I am currently struggling with two dropdowns where the data from mysql fetches not correcly.

The first dropdown is a list of locations followed by the second dropdown that must show the dates available.

here is the code of the requested php:

<?php
require('base.php');
switch(@$_REQUEST['location']){
    case 'RD':
        $query = mysql_query("SELECT * FROM `courses` where location = 'Dubai'");
        $row = mysql_fetch_array($query);
        while($row = mysql_fetch_array($query))
        {
        $locdata = array_push($locdata, echo $row['day'].' '.$row['date'].' '.$row['month']);
        }
        break;
    case 'UT': 
        $locdata=array( 'Monday 22 August', 'Tuesday 23 August');
        break;
    case 'NY':
        $query = mysql_query("SELECT * FROM `cursussen` where locatie = 'New York'");
        $row = mysql_fetch_array($query);
        while($row = mysql_fetch_array($query))
        {
        $locdata = array_push($locdata, echo $row['dag'].' '.$row['datum'].' '.$row['maand']);
        }
        break;
    case 'AM':
        $query = mysql_query("SELECT * FROM `cursussen` where locatie = 'Amsterdam'");
        $row = mysql_fetch_array($query);
        while($row = mysql_fetch_array($query))
        {
        $locdata = array_push($locdata, echo $row['dag'].' '.$row['datum'].' '.$row['maand']);
        }
        break;

    default: 
        $locdata=false;
}
if(!$locdata)echo 'Selecteer eerst een locatie';
else echo '<select name="locations"><option>'.join('</option>           <option>',$locdata).'</select>';

If all cases is set manually like in case UT, it works perfectly. How can append the data obtained from the database into an array?

First set up the array before your Switch using:

$locdata = array();

And then correct your push:

array_push($locdata, ..... etc )
case 'RD':
    $query = "SELECT * FROM `course` where locatie='Amsterdam'";
    $result = mysqli_query($link,$query);
    // if (!$result) {
    //   printf("Error: %s
", mysqli_error($link));
    //   exit();
    //}     
    $locdata = array();
    while($row = mysqli_fetch_array($result))
    {
        $temp = $row['day']." ".$row['date']." ".$row['month'];
        array_push($locdata, $temp);
    }
    break;

did the job