简体   繁体   中英

pulling data from mysql to dropdown box instead of data, the no value appears

I am pulling data from mysql to the dropdownbox. This is not my first time to do this, in the edit page I have 2-3 other dropdownbox that pull data from the database, but this one behaves differently.

在此处输入图片说明

<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']

Array indexes are case sensitive...

Meaning that you are selecting Username but using $row['UserName']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM