-2

I have a function which outputs a variable in a certain color depending on the contents of said variable, however it is currently outputting the same response to the IF statement even if the IF statement is not true

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>";
    }
}

Currently $time is always being outputted with #228B22 even if the value of $time = "Unavailable" or "CLOSED"

helmbert
  • 35,797
  • 13
  • 82
  • 95
Remel
  • 5
  • 2
  • 4
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jul 06 '15 at 17:07

1 Answers1

5

You have to change your first condition, because it's always 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>";}

In that case you can also change it to if-else statement:

if ($time != "Unavailable" && $time != "CLOSED"){
    echo "<center><font color=\"228B22\"><b>$time</b></font></center>";
} else {
    echo "<center><font color=\"B22222\">$time</font></center>";
}
marian0
  • 3,336
  • 3
  • 27
  • 37