我想弄清楚我应该如何构造一个if/else语句。PHP中的if/else结构
我明白基本if/esle应该如下;
<?php
if ($a > $b) {
echo "a is bigger than b";
} elseif ($a == $b) {
echo "a is equal to b";
} else {
echo "a is smaller than b";
}
?>
我不知道如何实现这个逻辑到我目前的声明。我认为,因为PHP是混合在HTML中它使我感到困惑:/
我敢肯定,这是非常错误的,但有人可以告诉我,它应该如何结构?
<form role="form">
<div class="btn-group" data-toggle="buttons">
<label class="btn btn-default <?php if ($status == '1') echo 'active btn-success' ; ?>">
<input type="radio" name="status" id="option1" value="1" autocomplete="off"> Active
</label>
<label class="btn btn-default <?php elseif ($status == '2') echo 'active btn-warning' ; ?>">
<input type="radio" name="status" id="option2" value="2" autocomplete="off"> Inactive
</label>
<label class="btn btn-default <?php else ($status == '3') echo 'active btn-danger' ; ?>">
<input type="radio" name="status" id="option3" value="3" autocomplete="off"> Not Found
</label>
</div>
</form>
我在NetBeans中看到的错误是;
Syntax error: unexpected elseif
我可以或应该只在每个标签上使用if语句吗?
为什么'elseif'&'else'。在每个标签中使用“if”。 –
不完全确定,但您可能想使用if/elseif/else语句的开放/关闭括号,它可能会修复您的错误。 – Epodax