doulongti5932 2017-12-10 05:28
浏览 40

根据SQL查询在下拉列表html中设置默认项?

Would this be the proper way to add a default value to a drop down menu it HTML?

$vendor_name is determine by a query to get an array of results; that is iterated through to create table rows in HTML. So this value changes dependent on the iteration.

<option value='$vendor_name'>$vendor_name</option>";
while($row = mysqli_fetch_array($result))
{
    echo "<option value='".$row['vendor_id']."'>".$row['name']."</option>";
}

When I attempt this it shows the default value; however, the table that is being created here is used to update an SQL table. If i change any other value in the row related to the $vendor_name without changing the $vendor_name it will not update. Is this because I set the default value?

  • 写回答

2条回答 默认 最新

  • duanla8800 2017-12-10 06:14
    关注

    Below is the correct way of setting default item in DropDown with PHP.

    <?php
    while ($row = mysqli_fetch_array($result)) {
      $selected = '';
      if ($vendor_name == $row['name']) {
        $selected = ' selected';
      }
      echo "<option value='" . $row['vendor_id'] . "'" . $selected . ">" . $row['name'] . "</option>";
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来