PHP comparing if equal to a string or text

Hi.

Fairly new to PHP - coming from a fairly fluent Classic ASP VBScript background.

  • PHP 5.x

  • Have a MySQL db

  • Have a [sale_status] column (Values are either “E” or “P” – For “Expired” or “Pending”, respectively).

  • Looping through the [sale_status] column to display the statuses - works fine.

  • I am trying to do a basic “If statement” where it will do one thing for “E” and another for whatever else.

  • The statement asks:


if {{sale_status}} == “E” {
echo (“YES”);
}
ELSE {
echo (“NO”);
}


  • I only get “NO” for ALL the records - including the “E” records.

  • I know the {{sale_status}} is giving the correct data through the loop, because I removed the “if statement” and just “echoed” the {{sale_status}} and it outputs the correct respective values going down the page.

  • I have tried “===” and “==”, but same thing.

  • I got a little something when I did a “strcmp” or “strcasecmp”, but they were inconsistent.

  • Verified it is a type “varchar(50)” field in the MySQL db.

In Classic ASP, it would compare without an issue, but I know PHP has some different nuances that I have yet to learn regarding comparisons, and such.

If anyone could, please, help - that would be great.

Thank you!
Shane

You have too may curly brackets, curly brackets group statements in if clauses normal round brackets are used for comparison try this:

[php]
if ($sale_status == ‘E’) {
echo ‘YES’;
}
else {
echo ‘NO’;
}
[/php]

Don’t forget that you need to read the sale status from your database and assign it to the $sale_status variable.

Sponsor our Newsletter | Privacy Policy | Terms of Service