此代码从数据库中检索并显示客户的帐户信息,并预先选择与其信息相匹配的值。
问题在于,它不是从现有的“选择”或多选选项中进行选择,而是添加并选择具有相关值的新选项。我该如何纠正它,以便它从现有选项中进行选择?
<option selected="selected" value="<?php echo $rows['notifications']; ?>"><?php echo $rows['notifications']; ?></option>
完整代码为:
<?php
$result = mysql_query("SELECT * FROM customer_info WHERE customer_info.user_id=$user_id ") or die(mysql_error());
$row = mysql_fetch_array($result );
?>
<label>Notifications:</label><select name="notifications[]" class="multi" multiple="multiple" style="width:10em;">
<option selected="selected" value="<?php echo $rows['notifications']; ?>"><?php echo $rows['notifications']; ?></option>
<option value="New_Items">New items</option>
<option value="Sale_Items">Sale items</option>
<option value="Profile_Matches">Items matching my profile</option>
</select>
<label>Gift Program:</label>
<select name="gift_privacy" style="width:20em;">
<option selected="selected" value="<?php echo $rows['gift_privacy']; ?>"><?php echo $rows['gift_privacy']; ?></option>
<option value="Standard">Standard settings</option>
<option value="Gift_ID_Req">Require program ID</option>
<option value="Not_Enrolled">Do not enroll</option>
</select>
最佳答案
<label>Gift Program:</label>
<select name="gift_privacy" style="width:20em;">
<option <?php if($rows['notifaction] === "Standard") echo 'selected="selected'; ?> value="Standard">Standard settings</option>
<option <?php .... ?> value="Gift_ID_Req">Require program ID</option>
<option <?php .... ?> value="Not_Enrolled">Do not enroll</option>
</select>
关于php - 从现有选项中预选择“选择”或多选选项,而不是添加和选择新选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13459921/