douyong1974 2013-12-17 23:51
浏览 121

PHP将数据回显到HTML下拉菜单中

I have a HTML etc.. tags now what I want to achieve is upon a selection of ie. i want to load the related info from database to in a new tag with as many tags.

I am using PHP to do achieve this now at this point if for example i choose option1 then the query behind it retrieves relevant information and stores it in a array, and if I select option2 exactly the same is done.

The next step I made is to create a loop to display the results from array() but I am struggling to come up with the right solution to echo retrieved data into etc. As its not my strongest side.

Hope you understand what I am trying to achieve the below code will clear thing out.

HTML:

<select id="workshop" name="workshop" onchange="return test();">
                <option value="">Please select a Workshop</option>
                <option value="Forex">Forex</option>
                <option value="BinaryOptions">Binary Options</option>
            </select>

PHP:

   $form = Array();

if(isset($_POST['workshop'])){

$form['workshop'] = $_POST['workshop'];
$form['forex'] = $_POST['Forex'];
$form['binary'] = $_POST['Binary'];


//Retrieve Binary Workshops 
if($form['workshop'] == 'Forex'){
    $sql2 = "SELECT id, course, location FROM courses WHERE course LIKE '%Forex%' OR  course LIKE '&forex%'";
        $query2 = mysqli_query($link, $sql2);
            while($result2 = mysqli_fetch_assoc($query2)){


               //The problem I am having is here :/ 

            echo "<select id='Forex' name='Forex' style='display: none'>";
            echo "<option value='oko'>.$result[1].</option>";
            echo "</select>";
            print_r($result2);echo '</br>';
        }
    }else{
        $sql = "SELECT id, course, location FROM courses WHERE course LIKE '%Binary%' OR course LIKE '%binary%'";
        $query = mysqli_query($link, $sql);
            while($result = mysqli_fetch_assoc($query)){
                print_r($result);echo '</br>';

        }
    }
}
  • 写回答

2条回答 默认 最新

  • drll42469 2013-12-18 00:13
    关注

    Try this code:

    $query2 = mysqli_query($link, $sql2);
    
    echo "<select id='Forex' name='Forex' style='display: none'>";
    while($result2 = mysqli_fetch_assoc($query2)){
      echo "<option value='oko'>{$result['course']}</option>";
    
    }
    echo "</select>";
    echo '</br>';
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。