douduan9391 2017-02-09 06:21
浏览 40
已采纳

如何在php中填充数据库中的Dropdown值

Hello Friends how to get data from database in Drop-down list?

This is my code but i can't get data in Drop-down list,

This is my php code.

public function System_parameter_dropdown_value() {
   $sql= " SELECT * FROM SYSTEM_PARAMETERS WHERE     PARAMETER_KEY='ROLE_TYPE'";
   $rs=  mysql_query($sql) or die(mysql_error());
   $option_list="<option value=0>Select Role Type</option>";
   while($data=  mysql_fetch_assoc($rs)) {
      $option_list.="<option value='$data[PARAMETER_KEY]'>
      $data[PARAMETER_VALUE]</option>";
   }
   return $option_list;
}

This is my html option list, When i run the code it's show nothing in Dropdown list

<label class="control-label" for="roleid"  style="padding-right: 80px;">ROLE TYPE</label>
   <select id="" name="roleid">
      <?php echo $option_list['PARAMETER_KEY']['PARAMETER_VALUE'];?>
   </select>

I am Stuck on this code , please Guide me How to Resolve it.

  • 写回答

4条回答 默认 最新

  • drci47425 2017-02-09 06:27
    关注

    Try some thing like this:

    $arr = array(1 => 'MP', 2 => 'UP');
    
    echo '<select>';
    foreach($arr as $key => $val)
    {
        echo '<option value="'.$key.'">'.$val.'</option>';
    }
    echo '</select>';
    

    It will generate html like:

    <select>
      <option value="1">MP</option>
      <option value="2">UP</option>
    </select>
    

    In your case it is like:

    <select id="" name="roleid">
      <?php echo System_parameter_dropdown_value();?>
    </select>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?