在这里,我有一个选择框,我要在其中显示以JSON格式存储在数据库中的值。如果存在该值,则显示所选值,否则显示默认选项Delete leads
选项。它无法正常工作。
<div class="col-md-7">
<select class="form-control" id="spm" name="spm" required style="">>
<option value=""> Delete Leads </option>
<?
foreach($slct_optn as $slct_optns)
{
$slctoptn = json_decode($slct_optns['spam_management'],1);
?>
<option value="7" <?php if($slctoptn['delete']==7) {?> selected="selected" <? } ?>>1 Week Older</option>
<option value="30" <?php if($slctoptn['delete']==30) {?> selected="selected" <? } ?>>1 Month</option>
<option value="60" <?php if($slctoptn['delete']==60) {?> selected="selected" <? } ?>>2 Month</option>
<? }
?>
</select>
有人可以帮助我吗?
答案 0 :(得分:1)
我认为您可以像这样将$slctoptn['delete']
更改为$slctoptn[0]['delete']
变量:
<div class="col-md-7">
<select class="form-control" id="spm" name="spm" required style="">>
<option value=""> Delete Leads </option>
<?
foreach($slct_optn as $slct_optns)
{
$slctoptn = json_decode($slct_optns['spam_management'],1);
?>
<option value="7" <?php if($slctoptn[0]['delete']==7) {?> selected="selected" <? } ?>>1 Week Older</option>
<option value="30" <?php if($slctoptn[0]['delete']==30) {?> selected="selected" <? } ?>>1 Month</option>
<option value="60" <?php if($slctoptn[0]['delete']==60) {?> selected="selected" <? } ?>>2 Month</option>
<? }
?>
</select>
这将使用'delete'
父数组内唯一的$slctoptn
数组。