这里有一个选择框,我想在其中显示以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>
有人能帮我吗?
我认为您可以将$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>
这将使用$slctoptn
父数组中唯一的'delete'
数组。