[英]How i can list selected value as selected and other values as listin php foreach loop
I want to display selected value as selected and others list in drop down.how it is possible inforeach 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 } ?>
but now listing morethan onetime(look uploaded image) 但现在列出的不止一次(看上传的图片)
how i can change listing value display ones.? 我如何更改列表值显示的?
Either do the foreach over possible values, and check whether the value is in selected values (only one option tag in your code then since you'r printing it in a loop): 要么对可能的值进行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 } ?>
Or print them as you do, but then don't use a for loop to print them - use a loop or better an associative array to check whether each of them is selected. 或按您的方式打印它们,但是不要使用for循环来打印它们-使用循环或更好的关联数组来检查是否选择了它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.