doubi5520 2018-06-22 04:42
浏览 44

在PHP中如何更新下拉列表值

How to Update Dropdown list value

<div class="form-group">

<label for="exampleSelect1" class="col-lg-2 control-label">Country</label>

<div class="col-lg-4">

<select class="form-control" id="exampleSelect1" value="<?php echo 

$raw['country'];?>" name="country" >

        <option>INDIA</option>
        <option>US</option>
        <option>UK</option>
        <option>BHUTAN</option>
        <option>CHINA</option>

      </select>

      </div>

    </div>
  • 写回答

2条回答 默认 最新

  • doupu0619 2018-06-22 05:00
    关注

    What I think is that you want to display dropdown list values from database . If that's the case , then here is the solution :-

    function get_countries(){   
    $sql_get_countries = "select *                        
                          from ".main::$db_countries."                        
                          where continent_code = '".$_SESSION['continent_id']."'"             ;                       
    $res_get_countries = mysql_query ($sql_get_countries) ; 
    if (mysql_num_rows ($res_get_countries) > 0){
        $i = 0 ;
        while ($row_get_countries = mysql_fetch_object ($res_get_countries)){
            $tmp = array(
                'name'=>$row_get_countries->name,               
                'number'=>$row_get_countries->number
            );
            $this->get_countries[$i++] = $tmp ;
        }
    }
    return $this->get_countries ;
    }
    

    Here the country table has continent code in it .

    Now the front-end:-

    $country_array = $mp->get_countries() ;
    
    <div class="item form-group">
    
                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="country">Country<span class="required">*</span>
    
                        </label>
    
                        <div class="col-md-6 col-sm-6 col-xs-12">
    
                          <select class="form-control" id="country">
    
                            <option value="0">Choose Country</option>
    
                            <?php
    
                            foreach($country_array as $key=>$val){
    
                            ?>
    
                                <option value="<?=$val['number'];?>"><?=$val['name'];?></option>
    
                            <?php
    
                            }
    
                            ?>
    
                          </select>
    
                        </div>
    
                      </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器