简体   繁体   English

PHP的两个依赖下拉列表MySQL查询获取数组

[英]php two dependent dropdowns mysql query fetch to array

I am currently struggling with two dropdowns where the data from mysql fetches not correcly. 我目前在两个下拉列表中苦苦挣扎,其中来自mysql的数据无法正确获取。

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的代码:

<?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. 如果像情况UT一样手动设置所有情况,则效果很好。 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\n", 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 做这份工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM