dongzhang6677 2016-08-20 15:40
浏览 50

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?

  • 写回答

2条回答 默认 最新

  • dongmei6426 2016-08-20 16:33
    关注

    First set up the array before your Switch using:

    $locdata = array();
    

    And then correct your push:

    array_push($locdata, ..... etc )
    
    评论

报告相同问题?

悬赏问题

  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?