只有在满足php变量条件的情况下,我才能显示我的选择选项值



我有5个变量

$first ="first";
$second = "second";
$third = "third";
$fourth = "fourth";
$fifth = "fifth";

我在html 中有这个选择选项

<select name="e1" id="year" class="form-control" required="required">
<option value="" selected="selected" style="background: #0356e8;color: white;">-  -</option>
<option value="Attend To" style="background: #fd0303;color: white;">Attend To</option>
<option value="Explore" style="background: #fd7803; color: white;">Explore</option> 
<option value="Prompt" style="background: #fdd303; color: white;">Prompt</option>
<option value="Unaided" style="background: #58d95e; color: white;">Unaided</option>
<option value="Mastered" style="background: #12c4f9; color: white;">Mastered</option> 
<option value="Not Applicable" style="background: grey; color: black;">Not Applicable</option>
</select>

如果是$first ="first",那么第一个选项不应该显示<option value="Attend To" style="background: #fd0303;color: white;">Attend To</option>。。。这不应该显示。

如果$second = "second";,则第一个和第二个选项不应显示。。。

第三和第四也是如此。

回答您的问题:

$variable='first / second ... '; // one variable

如果你不想在同一页中使用IF,你可以在另一页使用功能:

function HowMuch($variable){
if($variable=='first'){
echo '      
<option value="Explore" style="background: #fd7803; color: white;">Explore</option> 
<option value="Prompt" style="background: #fdd303; color: white;">Prompt</option>
<option value="Unaided" style="background: #58d95e; color: white;">Unaided</option>
<option value="Mastered" style="background: #12c4f9; color: white;">Mastered</option> 
<option value="Not Applicable" style="background: grey; color: black;">Not Applicable</option>';
}elseif($variable=='second '){
echo '  
<option value="Prompt" style="background: #fdd303; color: white;">Prompt</option>
<option value="Unaided" style="background: #58d95e; color: white;">Unaided</option>
<option value="Mastered" style="background: #12c4f9; color: white;">Mastered</option> 
<option value="Not Applicable" style="background: grey; color: black;">Not Applicable</option>';
}
}

现在选择的页面位于:

<select name="e1" id="year" class="form-control" required="required">
<option value="" selected="selected" style="background: #0356e8;color: white;">-  -</option>
HowMuch($variable); //variable contains first or second..
</select>

最新更新