Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将数据从mysql拉到下拉框而不是数据,则不显示任何值_Php_Html_Mysql - Fatal编程技术网

Php 将数据从mysql拉到下拉框而不是数据,则不显示任何值

Php 将数据从mysql拉到下拉框而不是数据,则不显示任何值,php,html,mysql,Php,Html,Mysql,我正在将数据从mysql拉到dropdownbox。这不是我第一次这样做,在编辑页面中我有2-3个从数据库中提取数据的下拉框,但是这个下拉框的行为不同 <label>User Name</label><br> <select name="UserName" id="usernameSentakushi"> <option value="" <?php echo($UserName==''?' selected="select

我正在将数据从mysql拉到dropdownbox。这不是我第一次这样做,在编辑页面中我有2-3个从数据库中提取数据的下拉框,但是这个下拉框的行为不同

<label>User Name</label><br>
<select name="UserName" id="usernameSentakushi">
      <option value="" <?php echo($UserName==''?' selected="selected"':'');?>>--</option>
      <?php
                   $setsu = dbSetsuzoku();
                   $sql = "SELECT DISTINCT `Username` FROM `playerdb`";
                   $usernameData="";
                   $result = $setsu->query($sql);
                    while ($row = $result->fetch(PDO::FETCH_ASSOC))
                     {
                        $selected = ($UserName==$row['UserName'])?'selected="selected"':'';
                        $usernameData.='<option value="'.$row['UserName'].'"'.$selected.'>'.$row['UserName'].' - '.$row['UserName'].'</option>';
                     }
                    echo $usernameData;
                    $setsu = null;
                  ?>
      </select>

用户名

没有
$row['UserName']
但是您应该在options语句中使用
$row['UserName']

数组索引区分大小写


这意味着您选择的是
用户名
,但使用
$row['Username']

显示呈现的html,而不是不显示问题并发布到垃圾邮件网站的图片显示生成的html在下拉列表中显示生成的html/代码输出哦,我知道了,数据库上的字段是Username,我认为sql查询不区分大小写,谢谢!