[英]How i can list selected value as selected and other values as listin php foreach loop
我想將選定的值顯示為選定的值,而其他的則顯示在下拉列表中。
<?php $physicaldata = explode(",",$physical);
?>
<select name="PEPhysical[]" multiple onchange="GetrestPhysical(this.value);">
<?php foreach ($physicaldata as $physical)
{?>
<option <?php if($physical == 'Normal'){ echo ' selected="selected"'; } ?> value="Normal" >Normal Person</option>
<option<?php if($physical == 'Deaf/Dumb'){ echo ' selected="selected"'; } ?> value="Deaf/Dumb">Deaf/Dumb</option>
<option<?php if($physical == 'Blind'){ echo ' selected="selected"'; } ?> value="Blind">Blind</option>
<option<?php if($physical == 'Physically Challenged'){ echo ' selected="selected"'; } ?> value="Physically Challenged">Physically Challenged</option>
<option <?php if($physical == 'Mentally Challenged'){ echo ' selected="selected"'; } ?>value="Mentally Challenged">Mentally Challenged</option>
<option <?php if($physical == 'With other Disability'){ echo ' selected="selected"'; } ?> value="With other Disability">With other Disability</option>
<?php } ?>
我如何更改列表值顯示的?
要么對可能的值進行foreach檢查,然后檢查該值是否在選定的值中(由於循環打印,所以代碼中僅包含一個選項標簽):
<?php foreach ($possibleValues as $possibleValue)
{?>
<option <?php
if($selectedValues[$possibleValue->id]){ echo ' selected="selected"'; }
?> value="<?php
echo $possibleValue->id
?>" ><?php
echo $possibleValue->description
?></option>
<?php } ?>
或按您的方式打印它們,但是不要使用for循環來打印它們-使用循環或更好的關聯數組來檢查是否選擇了它們。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.