我有三个真正的条件:
编辑:
#sell-status-no {
background-color: #fe220b;
margin: 0 auto;
width: 240px;
border: 1px solid #000000;
}
#sell-status-yes {
background-color: #25b116;
margin: 0 auto;
width: 240px;
border: 1px solid #000000;
}
if (($profit >= 10.00 && $markup_percentage >= 30.00) || ($profit
< 10.00 && $markup_percentage >= 30.00) ||
($profit >= 10.00 && $markup_percentage < 30.00)){
$status = "YES";
$div_id = 'sell-status-yes';
}
else $status = "no"; {
$div_id = 'sell-status-no';
}
<div id="<?php echo $div_id; ?>">
<h2>Sell Status: <?php echo $status; ?> <h2>
</div>基本上,如果任何条件都是正确的,我会输出一个带有绿色背景的div,上面写着“是”。如果为假,则框为红色,并使用NO一词。
但是,每当我遇到$profit < 10 & $markup_percentage > 30的情况时,就会出现假条件(红色框和否)?
我不知道为何会出现这种情况,所以我们希望有任何帮助或更好的解决办法来解决这个问题。
干杯
发布于 2014-12-13 13:59:18
牙套问题。如果您要格式化代码,您将看到以下内容
if (
($profit >= 10.00 && $markup_percentage >= 30.00)
||
($profit < 10.00 && $markup_percentage >= 30.00)
||
($profit >= 10.00 && $markup_percentage < 30.00)){
$status = "YES";
$div_id = 'sell-status-yes';
}
else $status = "no";
{
$div_id = 'sell-status-no';
}试着把它改成
if (
($profit >= 10.00 && $markup_percentage >= 30.00)
||
($profit < 10.00 && $markup_percentage >= 30.00)
||
($profit >= 10.00 && $markup_percentage < 30.00)){
$status = "YES";
$div_id = 'sell-status-yes';
}
else {
$status = "no";
$div_id = 'sell-status-no';
}还可以将条件简化为
if ($profit >= 10.00 || $markup_percentage >= 30.00){
$status = "YES";
$div_id = 'sell-status-yes';
}
else {
$status = "no";
$div_id = 'sell-status-no';
}发布于 2014-12-13 14:03:29
您的“否则”条件是语句
$status = "no"; 然后,您将拥有虚假的作用域块:
{
$div_id = 'sell-status-no';
}永远都会被执行。
还请注意,条件逻辑可以使用布尔代数进行简化。
if (($profit >= 10.00 && $markup_percentage >= 30.00) ||
($profit < 10.00 && $markup_percentage >= 30.00) ||
($profit >= 10.00 && $markup_percentage < 30.00)){是相同的
if (($markup_percentage >= 30.00) ||
($profit >= 10.00 && $markup_percentage < 30.00))编辑,根据mleko的完整答案,代码
else $status = "no"; {
$div_id = 'sell-status-no';
}是错误的和误导的。这两条语句都必须位于else块中:
else {
$status = "no";
$div_id = 'sell-status-no';
}https://stackoverflow.com/questions/27459548
复制相似问题