如何在代码点火器的选择框中显示从数据库中选择的值



这里有一个选择框,我想在其中显示以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'数组。

相关内容

  • 没有找到相关文章

最新更新