Rocco The Taco
Rocco The Taco

Reputation: 3777

PHP echo MySQL value in If/Else

I have a PHP echo value that displays a value from a MySQL database like this:

<?php echo($row_WADAHTG_TechProps["EmpType"]); ?>

I need to construct an if/else with this value but am getting a syntax error no matter how I try to arrange this:

<?php
if (echo($row_WADAHTG_TechProps["EmpType"]) = "6001") {
  echo "Have a good day!";
} else {
  echo "Have a good night!";
}
?>

Upvotes: 0

Views: 712

Answers (4)

Jack
Jack

Reputation: 1941

I use shorthand ternary operators for if/else conditions

($row_WADAHTG_TechProps["EmpType"] === "6001" ? echo "Yes" : echo "No");

Notice I'm strictly comparing $row_WADAHTG_TechProps["EmpType"] to "6001" as strings, therefore if either of them are integers, the condition will echo "No".

Upvotes: 1

Chris
Chris

Reputation: 33

what about

<?php
    if ($row_WADAHTG_TechProps["EmpType"] == "6001") {
        echo "Have a good day!";
    } else {
        echo "Have a good night!";
    }
?>

you have to compare a value with ==or === (if you also want to compare the type)

Upvotes: 1

brechmos
brechmos

Reputation: 1316

if ( $row_WADAHTG_TechProps["EmpType"] == "6001") {
   echo "Have a good day!";
 } else {
   echo "Have a good night!";
 }

Careful with the single '=' sign in the if statement as that is an assignment.

Upvotes: 1

echo_Me
echo_Me

Reputation: 37233

try that:

 <?php
      if ($row_WADAHTG_TechProps["EmpType"] == "6001") {
             echo "Have a good day!";
      } else {
             echo "Have a good night!";
      }
 ?>

Upvotes: 2

Related Questions