lundi 22 décembre 2014

PHP - IF Statement to compare / verify text

Fairly new to PHP - But I come from a fairly fluent Classic ASP VBScript background.


PHP 5.5 (?) - Somewhere in there. MySQL db.



  • Have a MySQL table with a column [sale_status]


  • [sale_status] has values of "E" or "P" ("Expired" or "Pending", respectively)




  • I am looping through the table with PHP, and it displays all the values correctly ("E" or "P")




  • I am trying to do an "IF Statement" to do something when the value is "E" and something other thing for anything else.




  • My "IF Statement reads like...":



    $salestatus = {{sale_status}}

    if ($salestatus == "E") {
    echo ("YES");
    } ELSE {
    echo ("NO");
    }



  • For this, I get NO for everything (E and P).




  • I have tried === and strcmp and strcasecmp, but get the same thing.




  • I KNOW the values from {{sale_status}} are correct, because I can just echo that variable through the loop, and it display all the correct values.




  • For some reason, though, it will not distinguish E from P, or whatever.




  • In Classic ASP, it would be as simple as (if {sale_status} = "E", then ...) - and it works.




  • I know PHP has its own nuances, so that is what I am trying to learn.




Help is appreciated.


Aucun commentaire:

Enregistrer un commentaire