如果是PHP函数中的Statement

时间:2015-07-06 17:06:48

标签: php function if-statement

我有一个函数,它根据所述变量的内容输出某种颜色的变量,但是它正在输出与IF语句相同的响应,即使IF语句不是真的

function info($ride) {
    $query = mysql_query("SELECT * FROM `qtd` WHERE `name` = '$ride'");
    $rideinfo = mysql_fetch_array($query);

    $time = $rideinfo["time"];

    if ($time != "Unavailable" || $time != "CLOSED") {
        echo "<center><font color=\"228B22\"><b>$time</b></font></center>";
    }

    if ($time == "Unavailable" || $time == "CLOSED") {
        echo "<center><font color=\"B22222\">$time</font></center>";
    }
}

即使$time$time = "Unavailable"的值

,目前始终使用#228B22输出"CLOSED" var newElement = element.parent().clone(true,true).html();

1 个答案:

答案 0 :(得分:5)

你必须改变你的第一个条件,因为它总是true

if ($time != "Unavailable" && $time != "CLOSED"){echo "<center><font color=\"228B22\"><b>$time</b></font></center>";}   
if ($time == "Unavailable" || $time == "CLOSED"){echo "<center><font color=\"B22222\">$time</font></center>";}

在这种情况下,您还可以将其更改为if-else语句:

if ($time != "Unavailable" && $time != "CLOSED"){
    echo "<center><font color=\"228B22\"><b>$time</b></font></center>";
} else {
    echo "<center><font color=\"B22222\">$time</font></center>";
}